# Quaternions

Eric Bainville - Mar 2007## Unit quaternions and rotations

A *unit quaternion* is a quaternion q of norm |q|=1. The set of unit quaternions is a
*non-commutative* multiplicative group. Given a unit quaternion q, let's define the function
r_{q} operating on 3-vectors as follows:

- r
_{q}(u) = q × u × q*

r_{q} has the following properties:

- r
_{q}(u) is a 3-vector: r_{q}is a transformation of R^{3}. - r
_{q}(a.u + b.v) = a.r_{q}(u)+b.r_{q}(v): r_{q}is a linear transformation of R^{3}. - <r
_{q}(u),r_{q}(v)> = <u,v> (preserves the dot product): r_{q}is an orthogonal transformation of R^{3}. - r
_{q}= r_{-q}: q and -q correspond to the same transformation. - r
_{1}is the identity. - r
_{q}^{-1}= r_{q*}: q and q* represent inverse transformations. - r
_{p}(r_{q}(u)) = r_{p×q}(u): p × q corresponds to r_{p}o r_{q}. - If x is the vector part of q, then r
_{q}(x) = x: x is invariant by r_{q}.

Developping the product, we can obtain the 3×3 matrix M_{q} of r_{q}, for q=(s,u):

s^{2}+u_{x}^{2}-u_{y}^{2}-u_{z}^{2} | 2(u_{x}.u_{y}-s.u_{z}) | 2(u_{x}.u_{z}+s.u_{y}) |

2(u_{x}.u_{y}+s.u_{z}) | s^{2}-u_{x}^{2}+u_{y}^{2}-u_{z}^{2} | 2(u_{y}.u_{z}-s.u_{x}) |

2(u_{x}.u_{z}-s.u_{y}) | 2(u_{y}.u_{z}+s.u_{x}) | s^{2}-u_{x}^{2}-u_{y}^{2}+u_{z}^{2} |

After reduction, it appears that det(M_{q})=|q|^{6}=1: r_{q} is a rotation.

Up to the identification of q and -q, r_{q} is an isomorphism between the
group of rotations in R^{3}, and the group of unit quaternions.

Computing the product of two rotations requires 16.mul+12.add in quaternion form, and 27.mul+18.add in
matrix form. Computing the image of a vector by a rotation requires 28.mul+20.add in quaternion form (using
two consecutive quaternion products), and 9.mul+6.add in matrix form. Computing M_{q} requires 10.mul+21.add.

Using quaternions is a faster and more stable way of composing a large number of rotations. To apply the rotation itself to any number of vectors (even to one vector, unless it is known to have two zero coordinates), it is more convenient to precompute the matrix form, then compute matrix-vector products.

Quaternions : Definitions | Top of Page | Quaternions : Conversions |