Eric Bainville - Mar 2007

Quaternion from rotation matrix

We have seen in the previous chapter how to obtain the 3×3 rotation matrix corresponding to unit quaternion q. We see here how to obtain q=(s,ux,uy,uz), one of the two opposite unit quaternions corresponding to a given rotation matrix M:


We first compute the four values:

Comparing these values (all between 0 and 4), we can identify the largest component of q in magnitude. Then we pick the three products involving this component in the following list to build a vector proportional to q. q is then obtained by normalizing this vector.

For example, suppose the largest component is ux, we should normalize the vector (4.s.ux,4.ux2,4.ux.uy,4.ux.uz). This guarantees the best stability in all cases, and the unit norm of the result.