What is the sequence of rotations applied by "getEulerFromQuaternion"?

Post Reply
andytgl
Posts: 6
Joined: Thu Jul 08, 2021 5:54 pm

What is the sequence of rotations applied by "getEulerFromQuaternion"?

Post by andytgl »

As in the title, how are the Euler angles provided by the getEulerFromQuaternion method computed?
What is the sequence of rotations (about x, y, z, but in which order?) and they are computed in a fixed frame or in a moving frame (intrinsic or extrinsic)?
Thanks!
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: What is the sequence of rotations applied by "getEulerFromQuaternion"?

Post by drleviathan »

Is this a question about the Bullet C++ API or the python API?

I ask because there is no getEulerFromQuaternion() in the C++ API proper, but there is an implementation in examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.h. For all I know the python API supplies a method with a similar name.

The example implementation looks like this:

Code: Select all

btVector3 b3RobotSimulatorClientAPI_NoDirect::getEulerFromQuaternion(const btQuaternion& quat)
{
        btScalar roll, pitch, yaw;
        quat.getEulerZYX(yaw, pitch, roll);
        btVector3 rpy2 = btVector3(roll, pitch, yaw);
        return rpy2;
}
So the question becomes: What does btQuaterion::getEulerZYX(yaw, pitch, roll) do?

I looked at the code and discovered... it is not clear! The comments do not say, and the reader would have to step through the math to figure it out. However, if I were to hazard a guess I would think the yaw-pitch-roll decomposition would be about the local up-right-forward axes in that order. In other words, the directions of the various axes are locked in the local-frame and each rotation in the sequence moves those axes relative to the original world-frame, while the angles are always applied in the local frame. This is the decomposition that would make the most sense to someone with layman's grasp of how to formulate rotations: such as a pilot sitting in the local-frame of an airplane.

All that said, I would ask: What do you really want to do? (In other words: Why do you think you need Euler angles?). I have come to the conclusion over the years that Euler angles suck and should be avoided when possible. It is better (e.g. less dangerous and fewer headaches) to store and supply rotations in quaternion format and to do rotation math to achieve what you want.
andytgl
Posts: 6
Joined: Thu Jul 08, 2021 5:54 pm

Re: What is the sequence of rotations applied by "getEulerFromQuaternion"?

Post by andytgl »

Thank you for your reply. I was referring to the "getEulerFromQuaternion" method in the python interface. I have just noticed that the output of help() says that

Code: Select all

getQuaternionFromEuler(...)
    Convert Euler [roll, pitch, yaw] as in URDF/SDF convention, to quaternion [x,y,z,w]
so is potentially using the same order of rotations as defined here: http://sdformat.org/tutorials?tut=specify_pose. Will verify and let you know if it is actually true
Post Reply