I have a quaternion, coming from a system with the following:(intertial sensor)

Right handed.
Forward direction: Y axis
Right direction: X axis
Up direction: Z axis

I need to convert this into a coordinate system that is: (Unreal engine)

Forward direction: X axis
Right direction: Y axis
Up direction: Z axis

I have tried negating the axis, and angle, I have tried switching values, i cannot get this to work. All help greatly appreciated! I am working in C#, with Microsoft.Xna.Quaternion.

  • 1
    \$\begingroup\$ Is your situation a duplicate of this SO question Convert quaternion from right-handed to left-handed coordinate system? \$\endgroup\$ – Pikalek Aug 30 '16 at 22:15
  • \$\begingroup\$ @Pikalek Reading the title i'd say yes, however as you read OP's question, it seems he's not really interested in right-left-handedness but instead in swapping the uses of the x and y axis \$\endgroup\$ – Brian H. Nov 3 '17 at 8:34

To convert the Quaternion, we need to convert the imaginary part (xyz) which represents the axis of rotation into the destination coordinate system. In this case, that means exchanging x & y while leaving z unchanged.

Then, because we've changed the handedness of our coordinate system, our angle takes the opposite sign (a +ve rotation in a right-handed coordinate system is a -ve rotation about the corresponding axis in a left-handed coordinate system). This leaves the real part (w) unchanged, since cos(theta) = cos(-theta), and negates the imaginary part, since sin(theta) = -sin(-theta)

Combining these two effects, we get the following:

Quaternion ConvertSensorToUnreal(float x, float y, float z, float w) {

    Quaternion output;
    output.x = -y;
    output.y = -x;
    output.z = -z;
    output.w = w;

    return output;
| improve this answer | |

Rotation - counter clockwise is +ve and clockwise is -ve

Rx(90)*Rz(-90)*Ry(90) will switch in the way you wanted. Either you perform these rotation using quaternions or convert them into DCM (Direction Cosine Matrix) and then perform the rotation and convert back to quaternions.

I hope this will solve your issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.