# How unique are Quarternions and what about the sign?

I want to track a robot's orientation in space and wanted to choose quaternions for their many advantages.

However I have a few questions that I haven't found to be solved anywhere. The method I use to get quaternions from a rotation matrix is the one by Bar-Itzhack (2000). I want to use the "version 3" method always whether or not the rotation matrix is imprecise since the method for precise matrix (version 1) also involves almost the same computational effort (contructing some matrix and getting eigen*)and this way it is more robust if my matrix happens to be imprecise. My questions regarding quaternions are the following:

1. How unique are they when tracking in 3D space? Can I track the rotations of the tool frame without worrying about going through discontinuities in space? (E.g. like with axis-angle representation when the angle gets close to 0° or 180° and even is undefined for those) And no arbitrary outcomes.

2. In the method mentioned above a special matrix is constructed from the rotation matrix and then the eigenvector of the highest eigenvalue is used as the resulting quaternion. I wanted to confirm the correctness with the following test. However the resulting fixed-angle is often negative. So I started to just negate the quaternion but I suspect that there may be cases where this is wrong, so what is the method to determine the sign? This is my verification method:

1. Get rotation matrix of a fixed rotation around an axis (e.g. +42° about x)
2. From this rotation, apply the linked method above (version 3) to get the quaternion.
3. Get a rotation matrix from the quaternion back (method used by Craig)
4. And finally I convert the rotation matrix back into fixed angle representation and see if the angle is the same.

Any help would be much appreciated.

On this project I am not using ROS, everything is self-build.

• Quaternions are unique. However, Rotation Matrices are not. Therfore expect discontinuities when converting back to a rotaton matrix at step 3 and 4. Depending on which method you use for conversion and how much did your frame move "in the quaternion form" you might get completely different angles back. – 50k4 May 8 '17 at 14:44
• @50k4 Thank you for your comment! But rotation matrices are unique. E.g. see here: math.stackexchange.com/questions/105264/… – ruffy May 8 '17 at 14:53
• @Chuck, I posted it as an answer, however I do not think I touched on all question points, that is the reason I posted in as a comment – 50k4 May 8 '17 at 14:57
• @ruffy Yes, it seems that the matrix itself is uneque. I might be wrong and the problems will only appear at step 4 not at step 3. – 50k4 May 8 '17 at 14:59
• Can you please post the code and test case that you're using? I can see the paper you linked that shows the method, but how are you calculating the eigenvalues and eigenvectors? What is Craig's method and how are you implementing it? What method are are you using to get to the fixed angle representation and how did you implement it? There are tons of places to go wrong, and it would be much faster to review the work that you've already done than to leave the rest of the site to speculate where it is possible to go wrong. Also, FYI, $q = -q$ but otherwise quaternions are unique. – Chuck May 9 '17 at 15:40