Book contents
Contents
raw Math
RAW Book Algebra Quaternions

Introduction to Quaternions

Robert Eisele

Quaternion Introduction

Quaternions were discovered by William Rowan Hamilton in the 19th century, in an attempt to extend the complex numbers \(\mathbb{C}\) to a larger field with the same finite-dimensional structure. No such commutative extension exists; dropping the requirement of commutativity, however, yields a consistent four-dimensional structure, the skew field \(\mathbb{H}\) of Hamiltonian quaternions.

Unit quaternions offer a compact, efficient way to represent rotations in 3D space. Compared to Euler angles or rotation matrices, they require less memory, are faster to compose, interpolate smoothly between orientations, and avoid gimbal lock, a singularity that afflicts other representations. These properties make them well suited for computer graphics and robotics. The underlying idea rests on Euler's rotation theorem: every rotation in 3D is a rotation about a single fixed axis.

Quaternions also appeared historically outside of rotations: Maxwell's original formulation of the electromagnetic equations used quaternion notation.

The construction extends the complex numbers with a second imaginary unit \(\mathbf{j}\) to reach three spatial dimensions. For complex numbers, \(\mathbf{i}^2=-1\); to fix the product \(\mathbf{i}\mathbf{j}\), Hamilton introduced a third unit \(\mathbf{k}\) with \(\mathbf{i}\mathbf{j}=\mathbf{k}\), which determines the entire algebra. The result is called the Hamilton rules:

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

From \(\mathbf{ijk}=-1\), multiply both sides by \(\mathbf{k}\): \(-\mathbf{k}=\mathbf{ijk^2}=-\mathbf{ij}\). Doing this for all three gives:

\[\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

\(1\) \(\mathbf{i}\) \(\mathbf{j}\) \(\mathbf{k}\)
\(1\) \(1\) \(\mathbf{i}\) \(\mathbf{j}\) \(\mathbf{k}\)
\(\mathbf{i}\) \(\mathbf{i}\) \(-1\) \(\mathbf{k}\) \(-\mathbf{j}\)
\(\mathbf{j}\) \(\mathbf{j}\) \(-\mathbf{k}\) \(-1\) \(\mathbf{i}\)
\(\mathbf{k}\) \(\mathbf{k}\) \(\mathbf{j}\) \(-\mathbf{i}\) \(-1\)

Definition of Quaternions

Define 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}\]

is a quaternion, forming a non-commutative but associative algebra over \(\mathbb{R}\) with basis \(\mathbf{1}, \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} \]

A pure quaternion has only the imaginary part:

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

Quaternion notations

There are several ways to write a quaternion:

\[\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})\]

Josiah Gibbs later simplified this notation using vector notation, which became the standard form for its readability.

Embedding Complex numbers and Real numbers

Real and complex numbers embed into quaternions via:

\[\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

\[+:\mathbb{H}\times\mathbb{H}\mapsto\mathbb{H}\]

Addition is component-wise, just like vectors:

\[\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 additive identity is \(\mathbf{0}=0+0\mathbf{i}+0\mathbf{j}+0\mathbf{k}\).

Quaternion Negation

\[-:\mathbb{H}\mapsto\mathbb{H}\]

Negation is component-wise:

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

Quaternion Subtraction

\[-:\mathbb{H}\times\mathbb{H}\mapsto\mathbb{H}\]

Subtraction is component-wise:

\[\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

\[\times:\mathbb{H}\times\mathbb{H}\mapsto\mathbb{H}\]

Multiplication uses the Hamilton rules:

\[\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}\]

Multiplication is not commutative, since the cross product itself is not commutative, but it remains associative.

The multiplicative identity is \(\mathbf{1}=1+0\mathbf{i}+0\mathbf{j}+0\mathbf{k}\):

\[\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}\]

and

\[\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

\[\times:\mathbb{H}\times\mathbb{H}\mapsto\mathbb{H}\]

For pure quaternions (real part zero), 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

\[\cdot:\mathbb{R}\times\mathbb{H}\mapsto\mathbb{H}\]

Scalar multiplication scales 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}\]

Similarly for \(\mathbf{q}\cdot s\).

Quaternion Dot Product

\[\cdot:\mathbb{H}\times\mathbb{H}\mapsto\mathbb{R}\]

Treating quaternions as 4D vectors, the dot product extends naturally:

\[\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:

\[\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

\[\overline{\cdot}:\mathbb{H}\mapsto\mathbb{H}\]

Like complex conjugation, quaternion conjugation flips the imaginary parts:

\[\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}\]

Alternative form:

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

So we have:

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

More conjugate 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: \(\overline{\mathbf{q}}=-\mathbf{q}\) and \(\mathbf{q_1}\times\mathbf{q_2}=\overline{\mathbf{q_2}\times\mathbf{q_1}}\). A quaternion equals its conjugate iff \(\mathbf{v}=\mathbf{0}\).

You can extract the scalar and vector parts using conjugation:

\[(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:

\[\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}\]

A useful property:

\[\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

The norm (magnitude):

\[|\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}}\]

The norm is multiplicative: \(|\mathbf{q}_1\times\mathbf{q}_2| = |\mathbf{q}_1|\cdot|\mathbf{q}_2|\). Also, \(|\mathbf{\overline{q}}|=|\mathbf{q}|\).

Quaternion Muliplicative Inverse

The multiplicative inverse:

\[ \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) \]

Verification:

\[\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}\]

For a unit quaternion, the inverse is just the conjugate:

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

Quaternion Division

Division via the inverse:

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

Quaternion Normalization

To normalize a quaternion to unit length:

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

De Moivre's Formula for Quaternions

De Moivre's formula extends to quaternions:

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

Proof by induction:

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

Using trig 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 quaternion exponential is defined by the Taylor series:

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

Separate the real and imaginary parts:

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

For the vector part \(\mathbf{v} = x\mathbf{i} + y\mathbf{j} + z\mathbf{k}\):

\[\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\]

So \(\mathbf{v}^2 = -|\mathbf{v}|^2\)

Let \(\alpha:= |\mathbf{v}|\):

\[\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\]

The series for 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}\]

So the quaternion exponential is:

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

Quaternion Natural Logarithm

Let \(\mathbf{q}=(w,\mathbf{v})\neq\mathbf{0}\) with \(\mathbf{v}\neq\mathbf{0}\), and define

\[ \hat{\mathbf{v}}:=\frac{\mathbf{v}}{|\mathbf{v}|}, \qquad \psi:=\operatorname{atan2}(|\mathbf{v}|,w)\in(0,\pi). \]

The principal natural logarithm is

\[ \log(\mathbf{q}) =\log|\mathbf{q}|+\hat{\mathbf{v}}\psi =\left(\log|\mathbf{q}|,\hat{\mathbf{v}}\psi\right). \]

For a positive real quaternion \((w,\mathbf{0})\) with \(w>0\), this reduces to the real logarithm \(\log w\). On the negative real axis the imaginary direction is not unique, so the quaternion logarithm is multi-valued there.

For a unit quaternion \(\hat{\mathbf{q}}\), the scalar term vanishes:

\[ \log(\hat{\mathbf{q}})=(0,\hat{\mathbf{v}}\psi). \]

Exponentiating the logarithm gives the polar decomposition of every nonzero, nonreal quaternion:

\[ \mathbf{q} =|\mathbf{q}|\exp\left(\hat{\mathbf{v}}\psi\right) =|\mathbf{q}|\left(\cos\psi+\hat{\mathbf{v}}\sin\psi\right). \]

Its vector part is therefore

\[ \mathbf{v} =\hat{\mathbf{v}}|\mathbf{v}| =\hat{\mathbf{v}}|\mathbf{q}|\sin\psi. \]

Logarithm and exponential are inverses:

\[\begin{array}{rl} \exp(\log(\mathbf{q})) &= \exp\left(\log|\mathbf{q}|+\hat{\mathbf{v}}\psi\right)\\ &= |\mathbf{q}|\left(\cos\psi+\hat{\mathbf{v}}\sin\psi\right)\\ &= |\mathbf{q}|\left(\frac{w}{|\mathbf{q}|}+\frac{\mathbf{v}}{|\mathbf{q}|}\right)\\ &= \mathbf{q} \end{array}\]

Quaternion Power

Because quaternion multiplication is not commutative, a quaternion exponent requires an order convention. With a chosen branch of \(\log\), define the right power by

\[ \mathbf{q}^{\mathbf{p}} :=\exp\left(\log(\mathbf{q})\times\mathbf{p}\right). \]

The corresponding left power \(\exp(\mathbf{p}\times\log(\mathbf{q}))\) can differ. When the exponent \(a\in\mathbb{R}\) is scalar, it commutes with every quaternion, so both conventions agree:

\[ \mathbf{q}^{a}=\exp\left(a\log(\mathbf{q})\right). \]

Using the polar decomposition directly yields

\[ \mathbf{q}^{a} =|\mathbf{q}|^a\exp\left(a\hat{\mathbf{v}}\psi\right) =|\mathbf{q}|^a\left(\cos(a\psi)+\hat{\mathbf{v}}\sin(a\psi)\right). \]

For integer \(a=n\), this is De Moivre's formula above. For noninteger \(a\), different logarithm branches can produce different values.

Representing Rotations with Unit Quaternions

This section states the rotation formulas and their properties. Where they come from, starting at a rotation in the plane and arriving at the sandwich product through reflections, is derived in the chapter on rotations with complex numbers and quaternions. The corresponding quaternion derivatives relate tangent motion on the unit sphere to body- and world-frame angular velocity.

A unit quaternion (versor) with \(|\mathbf{q}|=1\) has three degrees of freedom and represents a rotation or orientation in 3D. It sits on the unit hypersphere \(w^2+x^2+y^2+z^2=1\) in 4D Euclidean space \(\mathbf{S}^3\):

\[ \hat{\mathbf{q}} =\exp(\hat{\mathbf{v}}\psi) =(\cos\psi,\hat{\mathbf{v}}\sin\psi) =\left(\cos\frac{\phi}{2},\hat{\mathbf{v}}\sin\frac{\phi}{2}\right), \qquad \psi=\frac{\phi}{2}. \]

This represents a rotation by angle \(\phi\) around the axis \(\hat{\mathbf{v}} = \frac{x\mathbf{i}+y\mathbf{j}+z\mathbf{k}}{\sqrt{1-w^2}}\).

Writing \(\hat{\mathbf{v}}\) as the pure unit quaternion \((0,\hat{\mathbf{v}})\), its square is \(\hat{\mathbf{v}}^2=-1\). Multiplicativity of the norm and conjugation give the useful unit identities

\[ \left|\hat{\mathbf{q}}\times\overline{\hat{\mathbf{q}}}\right|=1, \qquad \left|\hat{\mathbf{q}}_1\times\hat{\mathbf{q}}_2\right|=1, \qquad \hat{\mathbf{q}}^{-1}=\overline{\hat{\mathbf{q}}}. \]

Rotations describe frame transformations. The notation \(^A\hat{\mathbf{q}}_B\) means the orientation of frame \(B\) relative to frame \(A\).

The inverse of a unit quaternion is its conjugate \(\overline{\hat{\mathbf{q}}}\), which reverses the rotation.

Rotation of a vector

To rotate a point \(\mathbf{p}\), embed it as a pure quaternion \((0, \mathbf{p})\) and rotate using \(\hat{\mathbf{q}}\):

\[\begin{array}{rl} (0, \mathbf{p}') &= \hat{\mathbf{q}} \times (0, \mathbf{p}) \times \hat{\mathbf{q}}^{-1} \\ &= \hat{\mathbf{q}} \times (0, \mathbf{p}) \times \overline{\hat{\mathbf{q}}} \end{array}\]

The result has zero real part; the vector part is \(\mathbf{p}'\). Note that quaternion multiplication is not commutative, so \(\hat{\mathbf{q}}\) and \(\hat{\mathbf{q}}^{-1}\) do not simply cancel. A more efficient formula exists in practice; see vector rotation using quaternions:

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

Unit quaternions are compact (four numbers vs. nine for matrices), numerically stable, and free from gimbal lock. The JavaScript library Quaternion.js implements this rotation together with the other operations introduced above.

Concatenating Rotations

Composing two rotations (first \(\mathbf{q_1}\), then \(\mathbf{q_2}\)) is just quaternion multiplication:

\[\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

To reverse a rotation, use the conjugate:

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

The non-uniqueness of vector rotation

The rotation \(\hat{\mathbf{q}}\) and \(-\hat{\mathbf{q}}\) represent the same rotation: a rotation by \(-\phi\) around \(-\hat{\mathbf{v}}\) is the same as \(\phi\) around \(\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 conjugates: \(-\overline{\hat{\mathbf{q}}}\) and \(\overline{\hat{\mathbf{q}}}\) represent the same rotation.