# How to deal with multiple representations of quaternions

I'm using a quaternion to represent the orientation in a kalman filter. My algorithm works fine until I rotate "upside down". I think this is because there seems to be multiple ways to represent the same orientation.

Suppose I have a quaternion that represents no rotation q = (1,0,0,0).

A 180 degree rotation about the x axis should result in the same end orientation as if I were to rotate 180 degree about the y axis. However, the resulting quaternion doesn't reflect this.

My quaternion for rotation 180 degrees about the x axis is: $q_{rx} = (0,1,0,0)$ and rotation 180 degrees about the y axis is $q_{ry} = (0,0,1,0)$

$$qrx * q = (0,1,0,0)$$ $$qry * q = (0,0,1,0)$$ But, like I said, these are the same orientation.

Am I thinking about this the wrong way?

EDIT: I think I have found my problem. I was trying to use a single quaternion to represent the orientation in the Kalman filter. Since there are multiple ways to represent a single orientation with a quaternion, the Kalman filter would go unstable at these orientations. What I did to fix the problem was to represent orientation as $\Delta q * q$ in the filter. The Kalman filter then only acts on $\Delta q$ and it only represents small rotations. At the end of each Kalman "predict" and "update" stage, I update $q$. Therefore, we never get the ambiguity of orientation I was experiencing before.

As an aside, it makes the calculations of the Jacobians for the Kalman filter considerably more complicated.

• I'm having trouble understanding what you're looking for, so I'm going to comment and you'll try to steer, OK? First, I'm not sure what you're thinking when you say "orientation." The nonreflective rotations (the ones with determinant $+1$) all preserve orientation in the sense they do not reflect the space across a line. Could you try to explain why you think they have different "orientations" in whatever sense you are thinking? – rschwieb Mar 24 '14 at 13:28
• By orientation, I'm thinking of the following: I have a global coordinate system and then a sensor coordinate system (say on a vehicle that can only undergo rotations). I'm trying to capture the orientation of the vehicle with respect to the global coordinate system. There is not a unique quaternion that can be used to represent this orientation. (I'll add to my question what I have found.) – EpicAdv Apr 1 '14 at 18:23
• Hmm, well quaternions can only be used to represent rotations in a single fixed frame, so maybe you would be better off doing these transformations in 4-d homogeneous coordinates. – rschwieb Apr 1 '14 at 21:38

## 1 Answer

I'm interpreting this all as the standard representation of $3$-d rotations using the conjugation action of unit quaternions on the "pure quaternions" (those with real part $0$).

The transformation represented by the quaternion $q_{rx}=(0,1,0,0)=i$ indeed rotates the pure quaternions around the $x$ axis. It leaves $i$ fixed (the $x$ axis), and maps $j\mapsto -j$, $k\mapsto -k$, so that the $y,z$ plane has experienced a $180$ degree rotation.

Similarly, the transformation represented by the quaternion $q_{ry}=(0,0,1,0)=j$ fixes the $y$ axis and turns the $x,z$ plane $180$ degrees.

Both of these are nonreflective rotations, and therefore preserve orientation. Therefore they have the same orientation, but they do not, of course, result in the same transformation.

Going back to what you said before your example, it is true that rotations have more than one representation in this scheme, but you will probably not be impressed by the difference. It's easy to see that a unit quaternion $q$ represents the same rotation as $-q$ does. A quick computation confirms that $(-q)^{-1}=-q^{-1}$, and then $(-q)x(-q)^{-1}=(-1)^2 qxq^{-1}=qxq^{-1}$ follows immediately.