Using body kinematics analysis to calculate orientation error between bodies

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Birgitt Peeters
Posts: 8
Joined: Tue Jan 11, 2022 2:16 am

Using body kinematics analysis to calculate orientation error between bodies

Post by Birgitt Peeters » Wed Dec 13, 2023 12:58 pm

Hi!

I've been trying to calculate the orientation error (in degrees along each rotation axis X/Y/Z) between the bodies of 2 models. One model was defined using medical images in a specific 3D pose, while the other model is simulated to that pose. The validation model was defined before and in it's neutral pose the coordinates are all zero, the testing model is identical to the validation model, but it's neutral pose is different from the pose of the validation model (and in its neutral pose the coordinates are zero). I ran inverse kinematics using different settings for the test model (coupling constraints and marker weights on the spine) and I would like to calculate the errors in body locations and orientations. So I ran the body kinematics analysis, calculating the error in body position is not an issue using the outputs from the analysis, however, the orientation is not working out. The issue is in the XYZ body-fixed Euler rotations that are reported as an output from the analysis. The difference in XYZ body-fixed Euler angles does not give any relevant information on the difference in XYZ orientation between the bodies. For example, the difference in Euler angles can be up to 30 degrees along certain axes, while the orientation of both bodies is very similar (i.e. there should only be a few degrees difference). I have been trying to write a code to convert the Euler angles to rotation matrices and find the absolute rotation differences, however, without any success.

So I was wondering whether anyone has a suggestion on how to get relevant orientation differences of the bodies out? Or if someone could explain in detail how the XYZ Euler rotations are defined in OpenSim, I would be very grateful!

Tags:

User avatar
Nicos Haralabidis
Posts: 196
Joined: Tue Aug 16, 2016 1:46 am

Re: Using body kinematics analysis to calculate orientation error between bodies

Post by Nicos Haralabidis » Wed Dec 13, 2023 2:05 pm

Hello Birgitt,

To get rotation matrix of a body in the ground you can do:

Code: Select all

... % load model, set states etc
bodySet = model_1.getBodySet();
body1 = bodySet.get('your_body');
body1RotationMatrix = body1.getTransformInGround(state).R();
I think you could also retrieve the transform of your desired body in model_1 by doing the necessary initializing and then redo the initializing for model_2, get the relevant body and then call method findTransformBetween() on that body using the previously determined transform - https://simtk.org/api_docs/opensim/api_ ... 902fd30aa3
That output will also be a transform, and you can get that rotation matrix (between the desired body in model1 and desired body in model2) and even determine the Euler angles. Transform.R() or Transform.R().convertRotationToBodyFixedXYZ()... something like that.

Hope that helps,

Nicos

User avatar
Birgitt Peeters
Posts: 8
Joined: Tue Jan 11, 2022 2:16 am

Re: Using body kinematics analysis to calculate orientation error between bodies

Post by Birgitt Peeters » Fri Dec 15, 2023 12:27 pm

Hi Nicos,

Thanks for your reply.
I think using the method findTransformBetween() will be the best way forward for my application, thank you for this info!

Best,
Birgitt

POST REPLY