Home › Forum › SOFA › Using SOFA › [SOLVED] Changing the position of a mesh in python
- This topic has 6 replies, 4 voices, and was last updated 6 years ago by Damien Marchal.
-
AuthorPosts
-
14 December 2018 at 11:42 #12597AnonymousInactive
How do I access the position of mesh in python. I tried to access through the mechanical object tag by the following:
self.mechanical = self.Scissors.createObject('MechanicalObject', showObject='1', src="@loader" ) position = self.mechanical.findData('position').value
But this give me a large list consisting of smaller lists containing 3 numbers.
[[1.1906100511550903, 5.980000019073486, 2.4926400184631348], [1.1906100511550903, 7.43612003326416, 2.4926400184631348], [1.9372400045394897, 8.846019744873047, 1.8829799890518188], [7.860889911651611, 2.255139989374257e-16, 3.6365199089050293], [6.349870204925537, 2.255139989374257e-16, 1.8927099704742432], [7.959199905395508, 5.980000019073486, 3.8707499504089355], [7.08128023147583, 5.980000019073486, 2.4926400184631348], [7.08128023147583, 7.43612003326416, 2.4926400184631348], [6.294620037078857, 8.910229682922363, 1.8578200340270996], [5.161280155181885, 10.05090045928955, 1.3730800151824951], [4.83480978012085, 8.548850059509277, 1.3027199506759644], [4.900949954986572, 8.859999656677246, 1.3147300481796265], [4.372350215911865, 8.132439613342285, 1.2494699954986572], [4.6478400230407715, 8.291489601135254, 1.2747600078582764], [4.83480978012085, 9.171150207519531, 1.3027199506759644], [4.6478400230407715, 9.428509712219238, 1.2747600078582764], [4.372350215911865, 9.587559700012207, 1.2494699954986572], [4.6630401611328125, 10.257699966430664, 1.2767000198364258], [4.135950088500977, 9.625, 1.2426400184631348], [4.135950088500977, 10.34529972076416, 1.2426700592041016], [3.4370899200439453, 9.171159744262695, 1.3027199506759644], [3.3876700401306152, 9.019049644470215, 1.3115899562835693], [3.080169916152954, 10.033499717712402, 1.3810800313949585], [3.6237499713897705, 9.42821979522705, 1.2747999429702759], [3.5910000801086426, 10.25220012664795, 1.2790600061416626], [3.3876700401306152, 8.700949668884277, 1.3115899562835693], [1.922029972076416, 2.255139989374257e-16, 1.8927099704742432], [3.3709499835968018, 8.860369682312012, 1.3147300481796265], [3.51705002784729, 8.410340309143066, 1.289680004119873], [3.7534499168395996, 8.197489738464355, 1.2605400085449219], [4.135950088500977, 8.095000267028809, 1.2426400184631348], [4.135950088500977, 2.255139989374257e-16, 1.2426400184631348], [0.31269899010658264, 5.980000019073486, 3.8707499504089355], [0.8002610206604004, 2.255139989374257e-16, 2.9623100757598877], [0.04558819904923439, 2.255139989374257e-16, 5.142789840698242], [0.08263110369443893, 2.255139989374257e-16, 5.920420169830322], [0.31269899010658264, 5.980000019073486, 6.804530143737793], [1.9768699407577515, 8.909540176391602, 8.81721019744873], [1.1906100511550903, 7.436110019683838, 8.182640075683594], [2.259510040283203, 2.255139989374257e-16, 8.97741985321045], [1.1906100511550903, 5.980000019073486, 8.182640075683594], [2.220439910888672, 9.25901985168457, 8.956430435180664], [3.7467000484466553, 8.20143985748291, 9.41409969329834], [3.51705002784729, 8.410340309143066, 9.385600090026855], [3.3876700401306152, 8.700949668884277, 9.363690376281738], [3.4370501041412354, 9.171070098876953, 9.372559547424316], [3.7534499168395996, 9.522509574890137, 9.414739608764648], [3.1102800369262695, 10.050399780273438, 9.302109718322754], [4.13601016998291, 10.345199584960938, 9.43262004852295], [4.055990219116211, 9.620809555053711, 9.431859970092773], [4.372350215911865, 9.587559700012207, 9.425809860229492], [4.83480978012085, 9.171150207519531, 9.372570037841797], [4.900949954986572, 8.859999656677246, 9.360549926757812], [5.43927001953125, 9.871109962463379, 9.21969985961914], [4.938889980316162, 10.159500122070312, 9.353150367736816], [4.754630088806152, 9.30996036529541, 9.385629653930664], [4.525199890136719, 2.255139989374257e-16, 9.41409969329834], [4.884270191192627, 8.70110034942627, 9.363690376281738], [4.83480978012085, 8.548850059509277, 9.372570037841797], [4.6478400230407715, 8.291489601135254, 9.400520324707031], [6.098549842834473, 9.198479652404785, 8.931699752807617], [7.230740070343018, 2.255139989374257e-16, 8.01928997039795], [7.08128023147583, 7.436110019683838, 8.182640075683594], [7.08128023147583, 5.980000019073486, 8.182640075683594], [7.959199905395508, 5.980000019073486, 6.804530143737793], [8.005729675292969, 2.255139989374257e-16, 6.676980018615723], [8.226309776306152, 2.255139989374257e-16, 5.142789840698242], [4.372350215911865, 8.132439613342285, 9.425809860229492], [3.8996500968933105, 8.132410049438477, 9.425820350646973], [3.7534499168395996, 9.522509574890137, 8.182640075683594], [4.135950088500977, 10.8100004196167, 8.182640075683594], [4.055990219116211, 9.620809555053711, 8.182640075683594], [4.372350215911865, 9.587559700012207, 8.182640075683594], [3.51705002784729, 8.410340309143066, 8.182640075683594], [3.7534499168395996, 8.197489738464355, 8.182640075683594], [4.055990219116211, 8.099189758300781, 8.182640075683594], [4.6478400230407715, 9.428509712219238, 8.182640075683594], [5.444049835205078, 10.334099769592285, 8.182640075683594], [4.83480978012085, 9.171150207519531, 8.182640075683594], [6.195580005645752, 9.531439781188965, 8.182640075683594], [4.900949954986572, 8.859999656677246, 8.182640075683594], [4.592919826507568, 10.744099617004395, 8.182640075683594], [3.51705002784729, 9.309659957885742, 8.182640075683594], [2.827850103378296, 10.334099769592285, 8.182640075683594], [3.3876700401306152, 8.700949668884277, 8.182640075683594], [3.3876700401306152, 9.019049644470215, 8.182640075683594], [2.076319932937622, 9.531439781188965, 8.182640075683594], [4.372350215911865, 8.132439613342285, 8.182640075683594], [4.6478400230407715, 8.291489601135254, 8.182640075683594], [4.83480978012085, 8.548850059509277, 8.182640075683594], [4.372350215911865, 8.132439613342285, 2.4926400184631348], [4.83480978012085, 8.548850059509277, 2.4926400184631348], [4.6478400230407715, 8.291489601135254, 2.4926400184631348], [4.6478400230407715, 9.428509712219238, 2.4926400184631348], [4.592919826507568, 10.744099617004395, 2.4926400184631348], [4.372350215911865, 9.587559700012207, 2.4926400184631348], [4.055990219116211, 9.620809555053711, 2.4926400184631348], [4.83480978012085, 9.171150207519531, 2.4926400184631348], [5.444049835205078, 10.334099769592285, 2.4926400184631348], [4.055990219116211, 8.099189758300781, 2.4926400184631348], [3.7534499168395996, 8.197489738464355, 2.4926400184631348], [3.51705002784729, 8.410340309143066, 2.4926400184631348], [4.900949954986572, 8.859999656677246, 2.4926400184631348], [6.195580005645752, 9.531439781188965, 2.4926400184631348], [3.6789801120758057, 10.744099617004395, 2.4926400184631348], [3.7534499168395996, 9.522509574890137, 2.4926400184631348], [3.3876700401306152, 9.019049644470215, 2.4926400184631348], [3.3876700401306152, 8.700949668884277, 2.4926400184631348], [2.827850103378296, 10.334099769592285, 2.4926400184631348], [3.51705002784729, 9.309659957885742, 2.4926400184631348], [2.076319932937622, 9.531439781188965, 2.4926400184631348], [2.348259925842285, 9.886679649353027, 2.0387299060821533], [2.813080072402954, 10.323100090026855, 1.9001100063323975], [3.605649948120117, 10.723999977111816, 1.7661800384521484], [4.135970115661621, 10.809599876403809, 1.739259958267212], [3.3286900520324707, 10.623800277709961, 8.874480247497559], [4.136529922485352, 10.809700012207031, 8.935819625854492], [2.836019992828369, 10.340100288391113, 8.78048038482666], [5.923719882965088, 9.88659954071045, 8.636420249938965], [5.458859920501709, 10.323100090026855, 8.775090217590332], [4.666200160980225, 10.723999977111816, 8.909040451049805], [4.437709808349609, 10.777799606323242, 1.7477400302886963], [5.436059951782227, 10.339900016784668, 1.8946199417114258], [5.908430099487305, 9.90414047241211, 2.033250093460083]]
14 December 2018 at 13:28 #12598RouvenBlockedHello Fayad,
the output you received is the coordinate of each individual node in your mesh. Each node has three dimensions. Can you specify what you mean by the position of a mesh?
Greetings,
Rouven14 December 2018 at 17:03 #12599AnonymousInactiveThats what I meant, apparently I have to change the position of all the points by iterating through them, Thanks. I just need now to access to rotation coordinates, do you have any idea?
Thanks in advance.
14 December 2018 at 17:06 #12600AnonymousInactiveAlso when I change the position of the mesh, only the nodes move, but not the visual model, do you know how can I move that too. Thanks.
17 December 2018 at 11:57 #12608HugoKeymasterHi Fayad,
To rotate an object, you need to use a TransformEngine.
Or you can do it manually using python.Regarding the visual model not following, is there a mapping making the correspondence between the mechanical and the visual model ?
Best
Hugo
19 December 2018 at 11:52 #12621AnonymousInactiveJust to clear things, what I want is the following:
I have a Rigid model that I want to control using the keys, I achieved controlling the x,y,z axes, but now I need to control the orientation/rotation of the model (quaternion), but I am not sure how to do it through python.
In addition, I am not sure how to link the mechanical object to the visual model (oglModel).
Best,
Fayad19 December 2018 at 23:28 #12627Damien MarchalBlockedHi Fayad,
We have in the STLIB plugin some class to ease the manipulation of rigid body from python.
The plugin is here:
https://github.com/SofaDefrost/STLIBMore specifically the code to ease the manipulation is at line 103 (the RigidDof class) at
https://github.com/SofaDefrost/STLIB/blob/master/python/splib/numerics/__init__.pyAll this code is drafted and we hope that the next version of the plugin SofaPython3 will solve all that removing the need of these.
There is also similar script in the Compliant plugin (that is already in Sofa). If I remember correctly it is in the python applications/plugins/Compliant/python/StructuralAPI.py
Regards,
EDIT: About the line
‘position = self.mechanical.findData(‘position’).value’
You can alternatively do
‘position= self.mechanical.position’ -
AuthorPosts
- You must be logged in to reply to this topic.