Page 1 of 1

Using body kinematics analysis to calculate orientation error between bodies

Posted: Wed Dec 13, 2023 12:58 pm
by birgitt.peeters
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!

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

Posted: Wed Dec 13, 2023 2:05 pm
by nicos1993
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

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

Posted: Fri Dec 15, 2023 12:27 pm
by birgitt.peeters
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