Quaternions and their relation to Rotation Matrices¶

Rotation matrices are not the most efficient way to describe a rotation: they have 9 elements; yet only 3 are actually needed to uniquely characterize a rotation. Another disadvantage of describing 3-dimensional rotations with rotation matrices is that the three axes of rotation, as well as the sequence of the rotations about these axes, have to be defined arbitrarily, with different sequences leading to different rotation angles. A more efficient way of characterizing a rotation is to use a vector, with the direction of the vector given by the axis of the rotation, and its length proportional to the size of the rotation, as shown in Fig. 62. Such a vector has only three parameters, and there is no sequence of multiple rotations involved. The orientation of the vector is given by the right hand rule, i.e. a rotation left, down, or clockwise (as seen from the subject) is described by a vector which points up, left, or forward, respectively.

If the length of this vector is uniquely related to the magnitude of the rotation, then it uniquely characterizes the rotation. Different notations can be found. Denoting the vector describing the rotation about an angle $$\theta$$ with $$\vec{v}$$ , we have

• $$| \vec{v} | = \theta$$ … axis angles
• $$| \vec{v} | = sin(\theta/2)$$ … quaternions
• $$| \vec{v} | = tan(\theta/2)$$ … rotation vectors

By convention, the vector describing the quaternion orientation is determined by the right-hand rule:

The theory of quaternions was invented and developed by Hamilton in the mid nineteenth century . Its original purpose was to define the ratio of two vectors, and hence to be able to rotate one vector into another by multiplication with a third vector. Hamilton found that he could not accomplish this by using 3-component vectors, but had to use 4-component vectors or quaternions.

A detailed treatment of quaternions and their elegant mathematical properties can be found in mathematical texts (); many papers on eye movements (), and papers in more technical journals . The following description of quaternions will cover only the essential properties of quaternions which describe rotations.

A quaternion q which uniquely characterizes a rotation by an angle $$\theta$$ about an axis $$\vec{n}$$ is given by

(1)$q = q_0 + (q_1 * i + q_2 * j + q_3 * k) = q_0 + \vec{q} \cdot \vec{I}$

where $$\vec q = \left( {\begin{array}{*{20}{c}} {{q_1}}\\ {{q_2}}\\ {{q_3}} \end{array}} \right)$$ , $$\vec I = \left( {\begin{array}{*{20}{c}} i\\ j\\ k \end{array}} \right)$$ , and i, j, k are defined by

\begin{split}\begin{aligned} i \cdot i & = -1 & j \cdot j & = -1 & k \cdot k & = -1 \\ i \cdot j & = k & j \cdot k & = i & k \cdot i & = j \\ j \cdot i & = -k & k \cdot j & = -i & i \cdot k & = -j \end{aligned}\end{split}

The elements $${q_0, q_1, q_2, q_3}$$ have the following properties:

(2)\begin{split}\begin{aligned} q_0 & = cos(\theta/2) \\ | \vec{q} | & = \sqrt{q_0^2 + q_1^2 + q_2^3 + q_3^2} = sin(\theta/2)\\ \vec{q} & \parallel \vec{n} \end{aligned}\end{split}

$$q_0$$ is often called the scalar component of the quaternion q, and $$\vec{q}$$ the vector component of q. $$\vec{q}$$ describes the orientation as shown in Fig. Fig. #figquatB, with the length of the vector given by :math:sin(theta/2). It follows from Eq (2) b that quaternions describing rotations have the length 1, i.e. $$\sqrt {\sum\limits_{i = 0}^3 {q_i^2} } = 1$$ , and are thus called unit quaternions. In general, the length of a quaternion does not have to be one. If it is different, then the quaternion describes a combined rotation and stretching of a vector ().

The connection between a quaternion q and a rotation matrix $$\mathbf{R}$$, both describing the rotation of a vector $$\vec{x}$$ about an axis $$\vec{n}$$ by an angle $$\theta$$, can be derived from the definition of quaternions in Eqns. (1) - (2).

(3)$q \circ \left( {\vec x \cdot \vec I} \right) \circ {q^{ - 1}} = \left( {{\bf{R}} \cdot \vec x} \right) \cdot \vec I$

Although the left side of Eq is a full quaternion, the scalar component evaluates to zero, and does therefore not appear on the right side. The inverse quaternion $$q^{-1}$$ is for unit quaternions given by

(4)$q^{-1} = q_0 - \vec{q}$

and the formula for the combination of two quaternions ($$"\circ"$$) is given below. The general formula for the inverse quaternion is

(5)$q^{-1} = \frac{q_0 - \vec{q}}{|q|^2}$

From the quaternion q in Eq (?), the corresponding rotation matrix R can be determined through

(6)$\begin{split}{\bf{R}} = \left( {\begin{array}{*{20}{c}} {q_0^2 + q_1^2 - q_2^2 - q_3^2}&{2({q_1}{q_2} - {q_0}{q_3})}&{2({q_1}{q_3} + {q_0}{q_2})}\\ {2({q_1}{q_2} + {q_0}{q_3})}&{q_0^2 - q_1^2 + q_2^2 - q_3^2}&{2({q_2}{q_3} - {q_0}{q_1})}\\ {2({q_1}{q_3} - {q_0}{q_2})}&{2({q_2}{q_3} + {q_0}{q_1})}&{q_0^2 - q_1^2 - q_2^2 + q_3^2} \end{array}} \right)\end{split}$

The inverse computation is given by

(7)$\begin{split}\vec q = 0.5*copysign\left( {\begin{array}{*{20}{c}} {\sqrt {1 + {R_{11}} - {R_{22}} - {R_{33}}} ,}\\ {\sqrt {1 - {R_{11}} + {R_{22}} - {R_{33}}} ,}\\ {\sqrt {1 - {R_{11}} - {R_{22}} + {R_{33}}} ,} \end{array}\begin{array}{*{20}{c}} {{R_{32}} - {R_{23}}}\\ {{R_{13}} - {R_{31}}}\\ {{R_{21}} - {R_{12}}} \end{array}} \right)\end{split}$

where $$copysign(x,y) = sign(y)*\left| x \right|$$ .

For combined rotations, care has to be taken with the sequence of quaternions: if we describe the first rotation about $$\vec{p}$$ with the quaternion $$p$$, and the following rotation about the head fixed axis parallel to $$\vec{q}$$ by the quaternion $$q$$, the combined rotation is given by

(8)$q \circ p = \,\,\sum\limits_{{\rm{i}} = {\rm{0}}}^{\rm{3}} {{{\rm{q}}_{\rm{i}}}\,{{\rm{I}}_{\rm{i}}}\,\, * } \,\,\sum\limits_{{\rm{j}} = {\rm{0}}}^{\rm{3}} {{{\rm{p}}_{\rm{j}}}\,{{\rm{I}}_{\rm{j}}}} \,\, = \,\,{\rm{(}}{{\rm{q}}_{\rm{0}}}{{\rm{p}}_{\rm{0}}}\, - \,\vec q\, \cdot \,\vec p\,{\rm{)}}\,\, + \,\,(\,{{\rm{q}}_{\rm{0}}}\,{\rm{\vec p}}\,\, + \,\,{{\rm{p}}_{\rm{0}}}\,{\rm{\vec q}}\,\, + \,\,{\rm{\vec q}}\, \times \,{\rm{\vec p}}\,{\rm{)}}\, \cdot \,{\rm{\vec I}}$

The right side of Eq is obtained by using the definitions of (i, j, k) in Eq (1). The sequence of the quaternions in Eq (8) is important, and the opposite sequence, $$p \circ q$$, would lead to a different orientation of the object, as has been shown in the previous chapter. For rotations about head fixed axes, $$"\circ"$$ can be read as “after”.

Rotation Vectors and their Relation to Quaternions¶

Since the scalar-component of a unit quaternion does not contain any information that is not already given by the vector part, it can be eliminated by using rotation vectors instead of quaternions. The rotation vector $$\vec{r}$$, which corresponds to the quaternion q describing a rotation of $$\theta$$ about the axis $$\vec{n}$$, is given by

(9)$\vec r = \frac{{\vec q}}{{{q_0}}} = \tan \left( {\frac{\theta }{2}} \right)\,\frac{{\vec q}}{{\left| {\vec q} \right|}} = \tan \left( {\frac{\theta }{2}} \right)\,\vec n$

with $$|q|$$ the length of $$\vec{q}$$ as defined in Eq (2).

Rotation Vectors and their Relation to Rotation Matrices¶

rotation vector!relation to rotation matrix

A vector $$\vec{x}$$ can be rotated by an angle $$\rho$$ about a vector $$\vec{n}$$ through

(10)$\begin{split}\begin{array}{l} \vec R(\vec n,\rho ) \cdot \vec x = (\vec n \cdot \vec x)\vec n + \vec n \times \vec x\sin \rho - \vec n \times (\vec n \times \vec x)\cos \rho \\ or\\ \vec R(\vec n,\rho ) \cdot \vec x = \vec x\cos \rho + \left( {1 - \cos \rho } \right)\left( {\vec n \cdot \vec x} \right)\vec n + \sin \rho \vec n \times \vec x \end{array}\end{split}$

The development of this parametrization of rotations can probably be attributed to , and the coefficients of the rotation vectors are sometimes referred to as Euler-Rodrigues parameters (, p. 20). The rotation vector corresponding to the rotation matrix R can be determined easily from the elements of the rotation matrix by

(11)$\begin{split}\vec r = \frac{1}{{1 + ({R_{11}} + {R_{22}} + {R_{33}})}}*\left[ {\begin{array}{{20}{c}} {{R_{32}} - {R_{23}}}\\ {{R_{13}} - {R_{31}}}\\ {{R_{21}} - {R_{12}}} \end{array}} \right]\end{split}$

To establish the relationship between rotation vectors and other descriptions of rotations such as Fick-angles, we have to know how to get the rotation vector for combined rotations. Using Eqns. (8) and (9) we get

(12)$r_q \circ r_p = \frac{r_q + r_p + r_q \times r_p}{1-r_q \cdot r_p}$

where $$\vec{r_p}$$ is the first rotation (about an axis parallel to $$\vec{r_p}$$ ), and $$\vec{r_q}$$ the second rotation (about a space fixed axis parallel to $$\vec{r_q}$$ ) . For example, with $${\vec r_p} = \left[ {\begin{array}{*{20}{c}} 0\\ {0.174}\\ 0 \end{array}} \right]$$ and $${\vec r_q} = \left[ {\begin{array}{*{20}{c}} 0\\ 0\\ {0.087} \end{array}} \right]$$ Eqn. (12) would describe a rotation of 20$$^\circ$$about the horizontal axis $$\vec{h_2}$$ , followed by a rotation of 10$$^\circ$$about the space-fixed vertical axis $$\vec{h_3}$$. According to our discussion above of active and passive rotations, the same formula can also be interpreted as a first rotation of 10$$^\circ$$about the vertical axis $$\vec{e_3}$$, followed by a second rotation of 20$$^\circ$$about the rotated, object-fixed axis $$\vec{e_2}$$ - which corresponds to the horizontal and vertical rotation in a Fick-gimbal. The rotation vector corresponding to the full Fick rotation matrix in Eqn. (8) in the previous chapter can be obtained by adding a third rotation about the (object-fixed) forward direction, $$\vec{e_1}$$. Denoting a rotation vector which describes a rotation about an axis $$\vec{n}$$ by an angle $$\theta$$ with $$\vec r\left( {\vec n,\theta } \right)$$, this leads to

(13)$\begin{split}\vec r({\vec e_1},{\psi _F}) = \frac{1}{{1 - \tan (\frac{{{\theta _F}}}{2})*\tan (\frac{{{\phi _F}}}{2})*\tan (\frac{{{\psi _F}}}{2})}}\left( {\begin{array}{*{20}{c}} {\tan ({\psi _F}/2) - \tan ({\theta _F}/2)*\tan ({\phi _F}/2)}\\ {\tan ({\phi _F}/2) + \tan ({\theta _F}/2)*\tan ({\psi _F}/2)}\\ {\tan ({\theta _F}/2) - \tan ({\phi _F}/2)*\tan ({\psi _F}/2)} \end{array}} \right)\end{split}$

where ($$\theta_F, \phi_F, \psi_F$$) are the Fick-angles. For Helmholtz-angles, the corresponding equation reads

\begin{split}\begin{aligned} \label{eq:Helmholtz2Rotvect} r & = r({e_2},{\theta _H}) \circ r({e_3},{\phi _H}) \circ r({e_1},{\psi _H}) \\ & = \frac{1}{{1 - \tan (\frac{{{\theta _H}}}{2})*\tan (\frac{{{\phi _H}}}{2})*\tan (\frac{{{\psi _H}}}{2})}}\left( {\begin{array}{*{20}{c}} {\tan ({\psi _H}/2) + \tan ({\theta _H}/2)*\tan ({\phi _H}/2)}\\ {\tan ({\phi _H}/2) + \tan ({\theta _H}/2)*\tan ({\psi _H}/2)}\\ {\tan ({\theta _H}/2) - \tan ({\phi _H}/2)*\tan ({\psi _H}/2)} \end{array}} \right)\end{aligned}\end{split}

Close to the reference position, the relations between Fick-angles, Helmholtz-angles, rotation vectors and quaternions can be approximated by the simple formula

$\begin{split}{\left[ {\begin{array}{{20}{c}} \psi \\ \phi \\ \theta \end{array}} \right]_{Fick}} \approx {\left[ {\begin{array}{{20}{c}} \psi \\ \phi \\ \theta \end{array}} \right]_{Helmholtz}} \approx 100*\left[ {\begin{array}{{20}{c}} {{r_1}}\\ {{r_2}}\\ {{r_3}} \end{array}} \right] \approx 100*\left[ {\begin{array}{{20}{c}} {{q_1}}\\ {{q_2}}\\ {{q_3}} \end{array}} \right]\end{split}$

where $$\theta, \phi, \psi$$ are given in degrees. In summary, while rotation matrices are often an easy way to establish a correspondence between measured values (e.g. induction coil voltages, or images) and the orientation of an object relative to a given reference orientation, rotation vectors and quaternions have proven to be more intuitive and efficient. They are non-redundant, using three parameters to describe the three degrees of freedom of rotations, they don’t require an arbitrarily chosen sequence of rotations, but describe orientation by a single rotation from the reference orientation to the current orientation, they form an intuitive way of parametrizing rotations by expressing them by their axis and size, and they allow for an easy combination of rotations.

Combined rotations with rotation vectors¶

For combined rotations, rotation vectors show the same sequences as the corresponding rotation matrices. Using rotation vectors, equation [eq:EyeHead] can be expressed as

${\vec r_{gaze}} = {\vec r_{head}} \circ {\vec r_{eye}}$

This can be rearranged to yield the rotation vector describing the orientation of our object with respect to the reference frame (e.g. eye in head), $$\vec{r_{eye}}$$ , as

${\vec r_{eye}} = \vec r_{head}^{ - 1} \circ {\vec r_{gaze}}$

The formula for the combination of two rotation vectors is given by [eq:rotvectMult] , and the inverse of a rotation vector can be determined easily by $${\vec r^{ - 1}} = - \vec r$$.