# Quaternions

## 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 the \(\mathbb{C}\), is a finite dimensional real vector space. It turned out that this is not possible. However, n \(\mathbb{C}\) encompassing mathematical object can be found if one can dispense with commutativity. This leads to the skew field of the Hamiltonian quaternions \(\mathbb{H}\).

In practice it shows that unit quaternions represent a compact and efficient representation of orientations or rotations in three-dimensional space. Compared to other attitude paremeters such as the Euler angle or the Direction Cosine Matrix, quaternions are much less computing-intensive, require 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 products are obtained:

\[\mathbf{ij}=-\mathbf{ji}=\mathbf{k}, \mathbf{jk}=-\mathbf{kj}=\mathbf{i}, \mathbf{ki}=-\mathbf{ik}=\mathbf{j}\\\mathbf{ji}=-\mathbf{k}, \mathbf{kj}=-\mathbf{i}, \mathbf{ik}=-\mathbf{j}\]

## 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

- Four dimensional vector \(\mathbf{q} \in\mathbb{R}^4\):

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

- An extension of the complex numbers, with a real part and three imaginary parts, or vector part:

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

- A composition of two complex numbers \(\alpha, \beta\in \mathbb{C}\), where the complex numbers do not commute with \(\mathbf{j}\), but satisfy \(\mathbf{j}\beta=\overline{\beta}\mathbf{j}\)

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

- As a tuple, consisting of scalar and vector part (pure quaternion part)

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

### Quaterion Addition

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

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

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

The negation of a quaternion or 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

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

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

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

The associative but not commutative multiplication of the quaternions \(\mathbf{q_1}\) and \(\mathbf{q_2}\) can be derived 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 \(\mathbf{v_1\times v_2}\neq\mathbf{v_2\times v_1}\).

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

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

### Quaternion Multiplication with scalar

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

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

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

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 v_2}\\\end{array}\]

### Quaternion Conjugate

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

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}} = -\frac{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 quite 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{1} = \overline{\mathbf{1}}\) and \(\mathbf{q}= \overline{\mathbf{q}}\Leftrightarrow \mathbf{v}=\mathbf{0}\).

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

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

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

## TODO

Unit quaternions are used for the representation of rotations. The conjugate of a unit quaternion represents a rotation by the same angle but in the opposite axis. In addition, the conjugate of a unit quaternion is also its inverse.

\[\overline{\mathbf{\hat{q}}}\times \hat{\mathbf{q}} = \hat{\mathbf{q}} \times \overline{\mathbf{\hat{q}}} = \mathbf{1}\]