raw book


Robert Eisele

Quaternion Introduction

Quaternions were discovered in the middle of the 19th century by William Rowan Hamilton, who has spent the rest of his life investigating their characteristics. Quaternions are derived from the theoretical question whether the field \(\mathbb{C}\) can be extended to a larger field which, like \(\mathbb{C}\), is a finite dimensional real vector space. It turned out that this is not possible. However, an \(\mathbb{C}\) enclosing mathematical object can be found if one can dispose of commutativity. This leads to the skew field or division ring of the Hamiltonian quaternions \(\mathbb{H}\).

In practice it shows that unit quaternions represent a compact and efficient representation of orientations/rotations in three-dimensional space, so that quaternions can be seen as spherical vectors. Compared to other attitude parameters such as Euler angles or the Direction Cosine Matrix, quaternions are much less computing-intensive, requiring less memory and are naturally suited for efficient interpolation of rotations. In addition, they do not have singularities, so they are immune to the so-called gimbal lock, which opens wide usage patterns in computer graphics but also in robotics. Quaternions are based on Euler’s rotation theorem, which states that a relative orientation of two coordinate systems can be described by the rotation about a single rotation axis.

Quaternions were also adapted in physics. For example, Maxwell’s equations were originally formulated with quaternions.

Originally, the idea was to extend complex numbers by another imaginary number \(\mathbf{j}\) in order to work in three-dimensional space. For complex numbers it is known that \(\mathbf{i}^2=-1\), but what is the product of \(\mathbf{i}\mathbf{j}\)? To solve this problem, Hamilton introduced another imaginary number \(\mathbf{k}\) and closed the system circularly, on the idea that \(\mathbf{i}\mathbf{j}=\mathbf{k}\). With this statement we can formulate the Hamilton rules:

\[ \mathbf{i}^2=\mathbf{j}^2=\mathbf{k}^2=\mathbf{ijk}=-1 \]

Using the base rule \(-1=\mathbf{ijk}\), we can multiply both sides by \(\mathbf{k}\) and get \(-\mathbf{k}=\mathbf{ijkk}=\mathbf{ijk^2}=-\mathbf{ij}\). If this is carried out for all three variables, the following identities, sometimes known as Hamilton's rules, are obtained:

\[\begin{array}{rl} \mathbf{ij}=-\mathbf{ji}&=\mathbf{k}\\ \mathbf{jk}=-\mathbf{kj}&=\mathbf{i}\\ \mathbf{ki}=-\mathbf{ik}&=\mathbf{j} \end{array}\]

which can also be represented with the following multiplication table


Definition of Quaternions

We call the four-dimensional vector space

\[\mathbb{H}:= \{w\cdot\mathbf{1} + x\cdot\mathbf{i} + y\cdot\mathbf{j} + z\cdot\mathbf{k} | w,x,y,z\in\mathbb{R}\}\]

the set of Hamiltonian quaternions and

\[\mathbf{q}:= w\cdot \mathbf{1} + x\cdot\mathbf{i} + y\cdot\mathbf{j} + z\cdot\mathbf{k} = w + x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\in\mathbb{H}\]

a quaternion, which represents a non-commutative but associative \(\mathbb{R}\)-algebra with unit \(\mathbf{1}\) and further linear independent elements \(\mathbf{i}, \mathbf{j}, \mathbf{k}\):

\[\begin{array}{rl} \mathbf{1} &:= (1, 0, 0, 0)\\ \mathbf{i} &:= (0, 1, 0, 0)\\ \mathbf{j} &:= (0, 0, 1, 0)\\ \mathbf{k} &:= (0, 0, 0, 1) \end{array} \]

Furthermore, we define a pure quaternion as a quaternion, which consists only of the imaginary part:

\[\mathbf{q} = (0, \alpha, \beta, \gamma)\]

Quaternion notations

For quaternions there are different interpretations and thus also different notations. A quaternion can be seen as

\[\mathbf{q} = (w, x, y, z) \]

\[\mathbf{q} = w + x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\]

\[\mathbf{q} = |\mathbf{q}|\cdot(\cos\theta+\hat{\mathbf{v}}\sin\theta)\]

\[\mathbf{q} = \alpha + \beta \mathbf{j}\]

\[\mathbf{q}=(w, \mathbf{v})\]

Around the twentieth century, Josiah Gibbs published his Vector Analysis, in which he presented this simplification of quaternions by means of vector writing. The notation prevails today in science and engineering, since it is far more compact.

Embedding Complex numbers and Real numbers

The real and complex numbers can be embedded into the quaternions by the following homomorphism:

\[\mathbb{R}\to\mathbb{H}, x\mapsto (x, 0,0,0)\]

\[\mathbb{C}\to\mathbb{H}, z\mapsto (\Re(z), \Im(z),0,0)\]

Operators of Quaternions

Quaternion Addition


The associative and commutative sum of \(\mathbf{q_1}\) and \(\mathbf{q_2}\) can be derived via the addition in a four dimensional vector space as follows:

\[\begin{array}{rl} \mathbf{q_1+ q_2} &:= (w_1+x_1\mathbf{i}+y_1\mathbf{j}+z_1\mathbf{k})+(w_2+x_2\mathbf{i}+y_2\mathbf{j}+z_2\mathbf{k})\\ &= (w_1+ w_2)+(x_1+ x_2)\mathbf{i} +(y_1+ y_2)\mathbf{j}+(z_1+ z_2)\mathbf{k}\\ &= (w_1 + w_2, \mathbf{v_1} + \mathbf{v_2}) \end{array}\]

The neutral element with respect to addition is the zero element \(\mathbf{0}=0+0\mathbf{i}+0\mathbf{j}+0\mathbf{k}\).

Quaternion Negation


The negation of a quaternion or the additive inverse of \(\mathbf{q}\) is given by the componentwise negation:

\[\begin{array}{rl} -\mathbf{q} &:= -w -x\mathbf{i} -y\mathbf{j} -z\mathbf{k}\\ &= (-w, -\mathbf{v}) \end{array}\]

Quaternion Subtraction


The difference of quaternions can now be defined as the addition with the additive inverse, but stays the componentwise subtraction:

\[\begin{array}{rl} \mathbf{q_1- q_2} &:= \mathbf{q_1 + (- q_2)}\\ &= (w_1+x_1\mathbf{i}+y_1\mathbf{j}+z_1\mathbf{k})-(w_2+x_2\mathbf{i}+y_2\mathbf{j}+z_2\mathbf{k})\\ &= (w_1- w_2)+(x_1- x_2)\mathbf{i} +(y_1- y_2)\mathbf{j}+(z_1- z_2)\mathbf{k}\\ &= (w_1 - w_2, \mathbf{v_1} - \mathbf{v_2}) \end{array}\]

Quaternion Multiplication


The multiplication of two quaternions \(\mathbf{q_1}\) and \(\mathbf{q_2}\) can be determined using the Hamilton rule as follows:

\[\begin{array}{rl} \mathbf{q_1\times q_2} &:= (w_1+x_1\mathbf{i}+y_1\mathbf{j}+z_1\mathbf{k})(w_2+x_2\mathbf{i}+y_2\mathbf{j}+z_2\mathbf{k})\\ &= w_1w_2 + w_1x_2\mathbf{i} + w_1y_2\mathbf{j} + w_1z_2\mathbf{k}+ x_1w_2\mathbf{i}+x_1x_2\mathbf{ii}+x_1y_2\mathbf{ij}+x_1z_2\mathbf{ik}+ y_1w_2\mathbf{j}+y_1x_2\mathbf{ji}+y_1y_2\mathbf{jj}+y_1z_2\mathbf{jk}+ z_1w_2\mathbf{k}+z_1x_2\mathbf{ki}+z_1y_2\mathbf{kj}+z_1z_2\mathbf{kk}\\ &= (w_1w_2 - x_1x_2 - y_1y_2 - z_1z_2)+(w_1x_2 + x_1w_2 + y_1z_2 - z_1y_2)\mathbf{i}+(w_1y_2 - x_1z_2 + y_1w_2 + z_1x_2)\mathbf{j}+(w_1z_2 + x_1y_2 - y_1x_2 + z_1w_2)\mathbf{k}\\ &=(w_1w_2 - \mathbf{v_1}\cdot \mathbf{v_2}, w_1\mathbf{v_2} + w_2\mathbf{v_1}+\mathbf{v_1}\times\mathbf{v_2}) \end{array}\]

In general, the multiplication is not commutative, that is \(\mathbf{q_1\times q_2}\neq\mathbf{q_2\times q_1}\) since the cross product does not commute: \(\mathbf{v_1\times v_2}\neq\mathbf{v_2\times v_1}\). However, it is associative, which means \((\mathbf{q_1}\times\mathbf{q_2})\times\mathbf{q_3} = \mathbf{q_1}\times(\mathbf{q_2}\times\mathbf{q_3})\)

The neutral element with respect to the multiplication is the one element \(\mathbf{1}=1+0\mathbf{i}+0\mathbf{j}+0\mathbf{k}\) which can be shown as follows:

\[\begin{array}{rl} \mathbf{q}\times\mathbf{1} &= (w, \mathbf{v})\times(1, \mathbf{0})\\ &= (w-\mathbf{v}\cdot\mathbf{0}, w\mathbf{0}+1\mathbf{v}+\mathbf{v}\times\mathbf{0})\\ &= (w, \mathbf{v})\\ &= \mathbf{q} \end{array}\]


\[\begin{array}{rl} \mathbf{1}\times\mathbf{q} &= (1, \mathbf{0})\times(w, \mathbf{v})\\ &= (w-\mathbf{0}\cdot\mathbf{v}, 1\mathbf{v}+w\mathbf{0}+\mathbf{0}\times\mathbf{v})\\ &= (w, \mathbf{v})\\ &= \mathbf{q} \end{array}\]

Multiplication of Pure Quaternions


If \(\mathbf{q}_1\) and \(\mathbf{q}_2\) are a pure quaternion, which means the real part \(w_1=w_2=0\), the quaternion multiplication simplifies to

\[\mathbf{q_1\times q_2}=( - \mathbf{v_1}\cdot \mathbf{v_2}, \mathbf{v_1}\times\mathbf{v_2})\]

Quaternion Multiplication with a scalar


Multiplying a quaternion with a scalar \(s\in\mathbb{R}\) scales the quaternion on all components:

\[\begin{array}{rl} s\cdot\mathbf{q} &:= (s, \mathbf{0})\cdot(w, \mathbf{v}) \\ &= (sw - \mathbf{0}\cdot\mathbf{v}, s\mathbf{v}+s\mathbf{0}+\mathbf{0}\cdot\mathbf{v})\\ &= (sw, s\mathbf{v}) \end{array}\]

The opposite direction \(\mathbf{q}\cdot s\) can be shown similarly.

Quaternion Dot Product


If we consider quaternions as a four-dimensional vector, we can simply expand the dot product to it:

\[\begin{array}{rl} \mathbf{q_1}\cdot \mathbf{q_2}&:=(w_1, x_1, y_1, z_1)\cdot(w_2,x_2,y_2,z_2)\\ &= w_1w_2+x_1x_2+y_1y_2+z_1z_2\\ &= w_1w_2+\mathbf{v_1}\cdot\mathbf{v_2}\\ \end{array}\]

An Interesting property is

\[\mathbf{q_1}\cdot \mathbf{q_2} = \dfrac{1}{2}(\mathbf{q}_1\overline{\mathbf{q}_2}+\mathbf{q}_2\overline{\mathbf{q}_1})\]

Quaternion Conjugate


In analogy to complex conjugation, we can define the conjugation on quaternions:

\[\begin{array}{rl} \overline{\mathbf{q}} &= w-x\mathbf{i}-y\mathbf{j}-z\mathbf{k}\\ &= (w, -x, -y, -z)\\ &= (w, -\mathbf{v})\\ \end{array}\]

We can express the conjugate also in a different way:

\[ \overline{\mathbf{q}} = -\dfrac{1}{2}(\mathbf{q}+\mathbf{iqi}+\mathbf{jqj}+\mathbf{kqk}) \]

and see that the following property holds for the quaternion conjugate:

\[\mathbf{q}\times\overline{\mathbf{q}} = (\mathbf{q}\cdot\mathbf{q}, \mathbf{0})\]

The conjugate has some more interesting properties:

\[\begin{array}{rl} \overline{\mathbf{q_1}\times \mathbf{q_2}} &= (w_1w_2 - \mathbf{v_1\cdot v_2}, -(w_1\mathbf{v_2}+w_2\mathbf{v_1}+\mathbf{v_1}\times\mathbf{v_2})) \\ &= \overline{\mathbf{q_2}}\times \overline{\mathbf{q_1}}\\ \overline{\mathbf{q_1} \pm \mathbf{q_2}} &= (w_1 \pm w_2, -(\mathbf{v_1} \pm \mathbf{v_2}))\\ &= \overline{\mathbf{q_1}}\pm\overline{\mathbf{q_2}}\\ \overline{(\overline{\mathbf{q}})} &= \mathbf{q}\\ \overline{\mathbf{q}}\times \mathbf{q} &= (w - \mathbf{v})\times(w + \mathbf{v})\\ &= ww - (-\mathbf{v})\cdot \mathbf{v} + w\mathbf{v}+(-\mathbf{v})w+(-\mathbf{v})\times \mathbf{v}\\ &= w^2 + \mathbf{v}\cdot\mathbf{v}\\ &= \mathbf{q}\times\overline{\mathbf{q}} \end{array}\]

For pure quaternions it can easily be shown that \(\overline{\mathbf{q}}=-\mathbf{q}\) and \(\mathbf{q_1}\times\mathbf{q_2}=\overline{\mathbf{q_2}\times\mathbf{q_1}}\) are also valid. In addition to that \(\mathbf{q}=\overline{\mathbf{q}}\Leftrightarrow \mathbf{v}=\mathbf{0}\) and as such \(\mathbf{1} = \overline{\mathbf{1}}\).

It is also worth mentioning that the conjugate can be used to extract the scalar and vector part of a quaternion:

\[(w, 0) = \dfrac{1}{2}(\mathbf{q} + \overline{\mathbf{q}})\]

\[(0, \mathbf{v}) = \dfrac{1}{2}(\mathbf{q} - \overline{\mathbf{q}})\]

Squared Quaternion Norm

The squared norm of a quaternion can be determined as follows:

\[\begin{array}{rl} |\mathbf{q}|^2 &:= w^2 + x^2+y^2+z^2 = \mathbf{q}\cdot \mathbf{q}\\ & = (w^2 + |\mathbf{v}|^2, \mathbf{0})\\ & = (w^2 + \mathbf{v}\cdot\mathbf{v}, \mathbf{0})\\ & = (w^2 + \mathbf{v}\cdot\mathbf{v}, -w \mathbf{v} + w \mathbf{v} + \mathbf{v}\times(-\mathbf{v}))\\ & = (w, \mathbf{v}) \times (w, -\mathbf{v})\\ & = \overline{\mathbf{q}}\times \mathbf{q} = \mathbf{q} \times \overline{\mathbf{q}}\\ \end{array}\]

Furthermore, the following property applies to squared norms:

\[\begin{array}{rl} |\mathbf{q_1}\times\mathbf{q_2}|^2 &= (\mathbf{q_1}\times\mathbf{q_2}) \times \overline{(\mathbf{q_1}\times\mathbf{q_2})}\\ &= \mathbf{q_1}\times\mathbf{q_2}\times \overline{\mathbf{q_2}}\times\overline{\mathbf{q_1}}\\ &= \mathbf{q_1}\times|\mathbf{q_2}|^2\times\overline{\mathbf{q_1}}\\ &= \mathbf{q_1}\times\overline{\mathbf{q_1}}|\mathbf{q_2}|^2\\ &= |\mathbf{q_1}|^2|\mathbf{q_2}|^2\\ \end{array}\]

Quaternion Norm

From the squared norm, the magnitude or length can be determined, which also represents the quaternion norm:

\[|\mathbf{q}| = \sqrt{|\mathbf{q}|^2} = \sqrt{\mathbf{q}\cdot\mathbf{q}}= \sqrt{\mathbf{q}\times\overline{\mathbf{q}}} = \sqrt{w^2+\mathbf{v\cdot v}}\]

For the norm of a quaternion one has \(|\mathbf{\overline{q}}|=|\mathbf{q}|\). Interestingly, the product of two quaternion norms gives the Euler four-square identity.

Quaternion Muliplicative Inverse

Generally, the multiplicative inverse can be defined as:

\[ \mathbf{q}^{-1} = \dfrac{\overline{\mathbf{q}}}{\mathbf{q}\times\overline{\mathbf{q}}} = \dfrac{\overline{\mathbf{q}}}{|\mathbf{q}|^2} = \left(\dfrac{w}{w^2 + |\mathbf{v}|^2}, -\dfrac{\mathbf{v}}{w^2 + |\mathbf{v}|^2}\right) \]

Which can be shown as follows:

\[\begin{array}{rl} \mathbf{q} \times \mathbf{q}^{-1} &= (w, \mathbf{v}) \times \left(\dfrac{w}{w^2 + |\mathbf{v}|^2}, -\dfrac{\mathbf{v}}{w^2 + |\mathbf{v}|^2}\right)\\ &= \mathbf{1}\\ \mathbf{q}^{-1} \times\mathbf{q} &= \left(\dfrac{w}{w^2 + |\mathbf{v}|^2}, -\dfrac{\mathbf{v}}{w^2 + |\mathbf{v}|^2}\right) \times (w, \mathbf{v})\\ &= \mathbf{1} \end{array}\]

The inverse has the following properties: \((\mathbf{q}^{-1})^{-1} = \mathbf{q}\) and \((\mathbf{q_1}\times \mathbf{q_2})^{-1} = \mathbf{q_2}^{-1}\times\mathbf{q_1}^{-1}\). It is obvious that in case of a unit quaternion, the inverse can be expressed as the conjugate of the quaternion:

\[\mathbf{\hat{q}}^{-1} = \overline{\mathbf{q}}\]

Quaternion Division

With the help of the multiplicative inverse, one can now also define the quotient of \(\mathbf{q_1}\) and \(\mathbf{q_2}\):

\[\dfrac{\mathbf{q_1}}{\mathbf{q_2}}:= \mathbf{q_1} \times \mathbf{q^{-1}_2}\]

Quaternion Normalization

To normalize a quaternion to a unit quaternion with length 1, we divide its components by the length of the quaternion, similar to vector normalization:

\[\hat{\mathbf{q}} := \dfrac{\mathbf{q}}{|\mathbf{q}|}\]

De Moivre's Formula for Quaternions

De Moivre's Formula can be extended from the Complex Numbers to Quaternions

\[\begin{array}{rl} \mathbf{q}^n &= (|\mathbf{q}|\cdot(\cos\phi+\hat{\mathbf{v}}\sin\phi))^n\\ &= |\mathbf{q}|^n(\cos(n\phi)+\hat{\mathbf{v}}\sin(n\phi)) \end{array}\]

This can be proven with induction as follows:

\[\begin{array}{rl} \mathbf{q}^{n+1} &= (|\mathbf{q}|\cdot(\cos\phi+\hat{\mathbf{v}}\sin\phi))^{n+1}\\ &= |\mathbf{q}|^{n+1}\cdot(\cos(n\phi)+\hat{\mathbf{v}}\sin(n\phi))\cdot(\cos\phi+\hat{\mathbf{v}}\sin\phi)\\ &= |\mathbf{q}|^{n+1}\cdot(\cos((n+1)\phi)+\hat{\mathbf{v}}\sin((n+1)\phi)) \end{array}\]

Using the trigonometric identities

\[\begin{array}{rl}\cos(\alpha + \beta) &= \cos(\alpha) \cos(\beta) - \sin(\alpha) \sin(\beta)\\ \sin(\alpha + \beta) &= \cos(\beta) \sin(\alpha) + \cos(\alpha) \sin(\beta)\end{array}\]

Quaternion Exponentiation

The quaternionic exponential is given by the Taylor series similar to the exponential function in \(\mathbb{R}\):

\[\exp(\mathbf{q}) = \sum\limits_{n=0}^{\infty }{\dfrac {\mathbf{q}^{n}}{n!}}\]

Since we can separate the real and imaginary parts of the quaternion, we only need a solution for the vector part:

\[\exp(\mathbf{q}) = \exp(w + \mathbf{v}) = e^w\cdot\exp(\mathbf{v})\]

Now since \(\mathbf{v} = x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\) it follows that

\[\mathbf{v}^2 = (x\mathbf{i} + y\mathbf{j} + z\mathbf{k})(x\mathbf{i} + y\mathbf{j} + z\mathbf{k}) =-x^2-y^2-z^2\]

Since we know that \(|\mathbf{v}|^2 = x^2 + y^2 + z^2\) it follows that \(\mathbf{v}^2 = -|\mathbf{v}|^2\)

If we now define \(\alpha:= |\mathbf{v}|\), we get

\[\mathbf{v}^2 = -\alpha^2, \mathbf{v}^3 = -\alpha^2\mathbf{v}, \mathbf{v}^4 = \alpha^4, \mathbf{v}^5 = \alpha^4\mathbf{v}, \mathbf{v}^6 = -\alpha^6, \dots\]

With this, we can then determine the series of the vector part:

\[\begin{array}{rl} \exp(\mathbf{v})&=\sum\limits_{n=0}^\infty\dfrac{\mathbf{v}^n}{n!}\\ &=1+\dfrac{\mathbf{v}}{1!} - \dfrac{\alpha^2}{2!} - \dfrac{\alpha^2\mathbf{v}}{3!}+\dfrac{\alpha^4}{4!}+\dfrac{\alpha^4\mathbf{v}}{5!}-\dfrac{\alpha^6}{6!}+\cdots\\ &=1+\dfrac{\alpha\mathbf{v}}{1!\,\alpha}-\dfrac{\alpha^2}{2!}-\dfrac{\alpha^3\mathbf{v}}{3!\,\alpha}+\dfrac{\alpha^4}{4!}+\dfrac{\alpha^5\mathbf{v}}{5!\,\alpha}-\dfrac{\alpha^6}{6!}+\cdots\\ &=\left(1-\dfrac{\alpha^2}{2!}+\dfrac{\alpha^4}{4!} - \dfrac{\alpha^6}{6!}\cdots\right) + \dfrac{\mathbf{v}}{\alpha}\left(\dfrac{\alpha}{1!}-\dfrac{\alpha^3}{3!}+\dfrac{\alpha^5}{5!}\cdots\right)\\ &=\cos\alpha +\dfrac{\mathbf{v}}{\alpha}\sin\alpha\\ &=\cos(|\mathbf{v}|) +\dfrac{\mathbf{v}}{|\mathbf{v}|}\sin(|\mathbf{v}|) \end{array}\]

Thus, the quaternionic exponential is

\[\exp(\mathbf{q}) = e^w\left(\cos(|\mathbf{v}|), \hat{\mathbf {v} }\sin (|\mathbf {v}|)\right)\]

Quaternion Natural Logarithm

To compute the logarithm, first consider the angle between the vector and scalar parts of the quaternion.

\[\psi = \arccos {\frac {w}{|\mathbf{q}|}} = \arcsin {\frac {|\mathbf {v}|}{|\mathbf{q}|}} = \arctan {\frac {|\mathbf {v}|}{w}}\]

Now the natural logarithm of a quaternion can be determined with

\[\begin{array}{rl} \ln(\mathbf{q})&=\left( \ln |\mathbf{q}|, {\frac {\mathbf {v} }{|\mathbf {v} |}}\psi \right) \end{array}\]

The natural logarithm is the inverse of the exponentiation:

\[\begin{array}{rl} \exp(\ln(\mathbf{q})) &= \exp\left( \ln |\mathbf{q}|+ {\frac {\mathbf {v} }{|\mathbf {v} |}}\arccos {\frac {w}{|\mathbf{q}|}} \right)\\ &= |\mathbf{q}| \exp\left({\frac {\mathbf {v} }{|\mathbf {v} |}}\arccos {\frac {w}{|\mathbf{q}|}} \right)\\ &= |\mathbf{q}| \left( \frac{w}{|\mathbf{q}|} + \frac {\mathbf {v} }{|\mathbf {v} |} \frac{|\mathbf {v} |}{|\mathbf{q}|} \right)\\ &= \mathbf{q} \end{array}\]

Representing Rotations with Unit Quaternions

A normalized quaternion, also known as a unit quaternion or versor with \(|\mathbf{q}|=1\), has only three degrees of freedom instead of four can be used to represent the orientation of a rigid body or coordinate frame in three-dimensional space. It can be seen as the points on a hyper-sphere embedded in a 4D Euclidean space \((w^2+x^2+y^2+z^2=1)\), parameterized by the quaternion \(\hat{\mathbf{q}}\in\mathbf{S}^3\), which can be viewed as a rotational object in three-dimensional space:

\[\hat{\mathbf{q}} = e^{\frac{\theta}{2}\hat{\mathbf{v}}} = \left(\cos\dfrac{\phi}{2}, \hat{\mathbf{v}}\sin\dfrac{\phi}{2}\right)\]

Here, the unit quaternion \(\hat{\mathbf{q}}\) is interpreted as a rotation with an angle \(\phi\) around the rotation axis \(\hat{\mathbf{v}} = \frac{x\mathbf{i}+y\mathbf{j}+z\mathbf{k}}{\sqrt{x^2+y^2+z^2}}=\frac{x\mathbf{i}+y\mathbf{j}+z\mathbf{k}}{\sqrt{1-w^2}}\).

A rotation can be seen as a change of the reference frame. If we are in reference frame \(A\) and want to rotate to frame \(B\), we can use the notation \(^A\hat{\mathbf{q}}_B\), or seen differently, \(^A\hat{\mathbf{q}}_B\) describes the orientation of frame \(B\) relative to frame \(A\).

The inverse \(\hat{\mathbf{q}}^{-1}\) of a unit quaternion equals its conjugate \(\overline{\hat{\mathbf{q}}}\) and represents a rotation by the same angle but in the opposite axis.

Rotation of a vector

A point in three dimensional space \(\mathbf{p}\) can be described with three numbers, but it's often useful to think of these coordinates as the vector part of a quaternion \((0, \mathbf{p})\). A rotation of this augmented point by a given unit quaternion \(\hat{\mathbf{q}}\) to get a new vector \(\mathbf{p}'\) is given by

\[(0, \mathbf{p}') = \hat{\mathbf{q}} \times (0, \mathbf{p}) \times \overline{\hat{\mathbf{q}}}\]

This quaternion will have zero real part as well, and so the Euclidean coordinates are given by the vector part \(\mathbf{p}'\). Of course the product above is a quaternion product, which is not commutative. That's why the \(\mathbf{q}\) and the \(\mathbf{q}^{-1}\) don't cancel out. Many quaternion implementations already use this formula. However, it is possible to derive a vector rotation using quaternions which requires less operations:

\[\mathbf{p}' = \mathbf{p} + 2\hat{\mathbf{v}}\times(\hat{\mathbf{v}}\times\mathbf{p} + w\mathbf{p})\]

A rotation using a unit quaternion is very compact and uses only four numbers instead of 9 in a rotation matrix. It also behaves numerically more stable and most importantly it avoids the gimbal lock, a sort of singularity in representing rotations.

Concatenating Rotations

The composition of two rotations, first \(\mathbf{q_1}\) and then \(\mathbf{q_2}\) corresponds to quaternion multiplication, allowing an efficient and numerically stable combination of rotations as the product of quaternions:

\[\begin{array}{rl} (0, \mathbf{p}'') &= \hat{\mathbf{q_2}} \times (0, \mathbf{p}') \times \overline{\hat{\mathbf{q_2}}} \\ &= \hat{\mathbf{q_2}} \times \hat{\mathbf{q_1}}\times (0, \mathbf{p}) \times \overline{\hat{\mathbf{q_1}}} \times \overline{\hat{\mathbf{q_2}}}\\ &= (\hat{\mathbf{q_2}} \times \hat{\mathbf{q_1}})\times (0, \mathbf{p}) \times (\overline{\hat{\mathbf{q_1}}} \times \overline{\hat{\mathbf{q_2}}})\\ &= (\hat{\mathbf{q_2}} \times \hat{\mathbf{q_1}})\times (0, \mathbf{p}) \times \overline{\hat{\mathbf{q_2}} \times \hat{\mathbf{q_1}}}\\ \end{array} \]

Inverse vector rotation

The inverse of a unit quaternion is represented as the conjugate. Using it, we can determine the inverse vector rotation as

\[(0, \mathbf{p}) = \overline{\hat{\mathbf{q}}} \times (0, \mathbf{p}') \times \hat{\mathbf{q}}\]

The non-uniqueness of vector rotation

The rotation by a unit quaternion \(\hat{\mathbf{q}}\) is not unique, as it represents the same rotation as \(-\hat{\mathbf{q}}\). This is because it performs a rotation by the angle \(-\phi\) around the axis \(-\hat{\mathbf{v}}\), which is equivalent to a rotation by the angle \(\phi\) around the axis \(\hat{\mathbf{v}}\):

\[\begin{array}{rl} (-\hat{\mathbf{q}})\times(0, \mathbf{p})\times\overline{(-\hat{\mathbf{q}})} &= \left(-\cos\dfrac{\phi}{2}, -\hat{\mathbf{v}}\sin\dfrac{\phi}{2}\right)\times(0, \mathbf{p})\times\left(-\cos\dfrac{\phi}{2}, -(-\hat{\mathbf{v}} \sin\dfrac{\phi}{2})\right)\\ &= \left(\cos\dfrac{\phi}{2}, \hat{\mathbf{v}}\sin\dfrac{\phi}{2}\right)\times(0, \mathbf{p})\times\left(\cos\dfrac{\phi}{2}, \hat{\mathbf{v}} \sin\dfrac{\phi}{2}\right)\\ &= \hat{\mathbf{q}}\times(0, \mathbf{p})\times\overline{\hat{\mathbf{q}}} \end{array}\]

The same applies to the conjugate; \(-\overline{\hat{\mathbf{q}}}\) performs the same rotation as \(\overline{\hat{\mathbf{q}}}\).