[Math] Transform roll, pitch, yaw from one coordinate system to another

quaternionsrotations

I'm trying to figure out how to transform a pose given with Euler angles roll (righthanded around X axis), pitch (righthanded around Y axis), and yaw (lefthanded around Z axis) from the Unreal Engine into a pose in a purely right-handed North, West, Up coordinate frame.

coordinate frames

I know the full rotation matrix is $R = R_z R_y R_x$, as Euler angles are applied in that order.

enter image description here

But, irritatingly, the Y axis switches direction, and the whole coordinate system is rotated.

How can I elegantly determine pose in my target reference frame? I'm open to quaternions.

Best Answer

The relationship between the two frames as you’ve drawn them is simple: rotate by an angle of $\pi/2$ radians counterclockwise around the z axis, then reflect through the plane perpendicular to y.

There isn’t going to be any elegance about it with Euler angles. Someone has already done the repulsive conversion from unreal to 3x3 matrix or to quaternions for you, so find that. Just pick one and stick with it.

By “handed” it sounds like you mean the choice of sign when expressing a rotation around an axis. If that bothering you then obviously you can swap direction by swapping signs. But like I said, if it’s coming out of unreal someone probably already has written a conversion to a normal right handed coordinate system. (That’s what I think of as handedness: an orientation assigned to a coordinate system, not a type of rotation.)

Performing the rotation and reflection is trivial using matrices or quaternions. Rotations by quaternions are of course famous. Reflections might be lesser known but they are pretty simple to describe: take the unit normal $n$ to your plane expressed a s a quaternion: then $x\mapsto nxn $ is the reflection.