# Quaternions

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,u_{x},u_{y},u_{z}), one of the two opposite unit
quaternions corresponding to a given rotation matrix M:

M_{xx} | M_{xy} | M_{xz} |

M_{yx} | M_{yy} | M_{yz} |

M_{zx} | M_{zy} | M_{zz} |

We first compute the four values:

- 4.s
^{2}= 1+M_{xx}+M_{yy}+M_{zz}, - 4.u
_{x}^{2}= 1+M_{xx}-M_{yy}-M_{zz}, - 4.u
_{y}^{2}= 1-M_{xx}+M_{yy}-M_{zz}, - 4.u
_{z}^{2}= 1-M_{xx}-M_{yy}+M_{zz}.

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.

- 4.s.u
_{x}= M_{zy}- M_{yz}, - 4.s.u
_{y}= M_{xz}- M_{zx}, - 4.s.u
_{z}= M_{yx}- M_{xy}, - 4.u
_{x}.u_{y}= M_{xy}+ M_{yx}, - 4.u
_{y}.u_{z}= M_{yz}+ M_{zy}, - 4.u
_{z}.u_{x}= M_{zx}+ M_{xz}.

For example, suppose the largest component is u_{x}, we should normalize the vector (4.s.u_{x},4.u_{x}^{2},4.u_{x}.u_{y},4.u_{x}.u_{z}).
This guarantees the best stability in all cases, and the unit norm of the result.

Quaternions : Quaternions and Rotations | Top of Page | Sitemap |