# Converting a quaternion in a right to left handed coordinate system

## Converting a quaternion in a right to left handed coordinate system

```I have a quaternion from an IMU that id like to represent in unity. The issue is that the sensor uses a right handed coordinate system while unity uses a left handed coordinate system. In order to have the rotations of the IMU reflect in unity correctly, I would need to remap the axis. How can I do this by altering the quaternion components?
Specifically, I would need to map
sensor   unity
forward  x        z
up       z        y
right    -y       x

I have seen multiple questions regarding this question especially this one.
Convert quaternion to a different coordinate system
However, it only explains a specific case where its a right hand to right hand remapping.
If possible, include an explanation without mathematics equations of how you would map any coordinate system to any other coordinate system.
```

A quaternion can be thought of as an angle-axis representation:

``````quaternion.xyz = sin(angle/2) * axis.xyz
quaternion.w = cos(angle/2)
``````

So, converting them between two coordinate systems can be broken down into two steps:

1. Map the axis into the new coordinate system.
2. If changing between left & right hand coordinates (eg. if there’s an odd number of axis negations or axis exchanges between the two), negate the angle.

Since `cos(-angle) = cos(angle)` and `sin(-angle) = -sin(angle)` this is the same as flipping the axis of rotation, negating the x, y, and z parts.

``````         sensor   unity
forward    x        z
up         z        y
right     -y        x
``````

We can combine these steps into:

``````Quaternion ConvertToUnity(Quaternion input) {
return new Quaternion(
input.y,   // -(  right = -left  )
-input.z,   // -(     up =  up     )
-input.x,   // -(forward =  forward)
input.w
);
}
``````