Quaternion

Quaternion is a adding operator Group. It isn’t a Field and the missing part is commutative of multiplication.

Format

\[q = a + bi + cj + dk\]

Algebra

\[\begin{split}i^2 = j^2 = k^2 = −1\\ ij = k, ji = −k\\ jk = i, kj = − i\\ ki = j, ik = − j\end{split}\]

Conjugate

\[q^* = a - bi - cj - dk\]

Norm

\[\|q\|=\sqrt{a^2 + b^2 + c^2 + d^2}\]

Inverse

\[q^{-1} = \frac {q^*} {\|q\|^2} = \frac {a - bi - cj - dk} {a^2 + b^2 + c^2 + d^2}\]
\[qq^{−1} = q^{−1}q = 1\]

Identity

For adding group, the identity element is real number \(0\). For multiplication, the identity element is real number \(1\).

Associativity

The associativity holds for every \(x, y, z \in G\) in both adding and multiplication:

\[x \ast (y \ast z) = (x \ast y) \ast z\]

Distributive

\[p(q + r) = pq + pr\]

Commutative

Only true for adding

\[p + q = q + p\]

Not true for multiplication.

\[pq \neq qp\]

DO NOT USE \(p/q\) since it isn’t clear whether it is \(pq^{-1}\) or \(q^{-1}q\).

## Quaternions for rotations

Vector

A vector in three-dimensional space can be expressed as a pure quaternion, a quaternion with no real part: \(q = 0 + bi + cj + dk\).

Rotation Matrix

A rotation can be expressed by a quaternion \(q\) if

\[\|q\| = 1\]

From quaternion to a rotation matrix

A rotation from one coordinate frame \(A\) to another frame \(B\) is given by the conjugation operation of transform quaternion \(q_R\) :

\[q_B = q_Rq_Aq^*_R\]

Assuming \(q_A\) represent a vector or a point in \(R^3\), we have

\[\begin{split}q_A = xi + yj + zk \\ q_R = a + bi + cj + dk\end{split}\]

The transform result is

\[\begin{split}\begin{split} q_B = q_Rq_Aq^*_R &= (a + bi + cj + dk)( xi + yj + zk )(a − bi − cj − dk)\\ &= [x(a^2 + b^2 − c^2 − d^2) + 2y(bc − ad) + 2z(ac + bd)]i\\ &+ [2x(ad + bc) + y(a^2 − b^2 + c^2 − d^2) + 2z(cd − ab)]j\\ &+ [2x(bd − ac) + 2y(ab + cd) + z(a^2 − b^2 − c^2 + d^2)]k \end{split}\end{split}\]

If we express this in a matrix formulation

\[q_B = Mq_A\]

in which

\[\begin{split}M = \begin{bmatrix} a^2 + b^2 − c^2 − d^2 & 2(bc − ad) & 2(ac + bd) \\ 2(ad + bc) & a^2 − b^2 + c^2 − d^2 & 2(cd − ab) \\ 2(bd - ac) & 2(ab + cd) & a^2 − b^2 − c^2 + d^2 \end{bmatrix}\end{split}\]

From a rotation matrix of angles to a quaternion

\[\begin{split}\begin{split} Trace(M) & = M_{11} + M_{22} + M_{33} \\ & = 2(3a^2 + b^2 + c^2 + d^2 - 1.5) \\ & = 2(3a^2 + (1 - a^2) - 1.5 \\ & = 2(2a^2 - 0.5) \\ & = 4a^2 - 1 \end{split}\end{split}\]

We can solve this equation for \(a\):

\[|a| = \sqrt\frac{Trace(M) + 1} 4\]

Once we have \(a\), we can obtain \(b\) from \(M_{11}\)

\[M_{11} = 2(a^2 + b^2 - 0.5) = 2(\frac{Trace(M) + 1}4 + b^2 - 0.5)\]
\[|b| = \sqrt{\frac{M_{11}} 2 + \frac {1 - Trace(M)} 4}\]

Similarly, \(c\) and \(d\) can be computed from \(M_{22}\) and \(M_{33}\).

\[|c| = \sqrt{\frac{M_{22}} 2 + \frac {1 - Trace(M)} 4}\]
\[|d| = \sqrt{\frac{M_{33}} 2 + \frac {1 - Trace(M)} 4}\]

From Euler angles to a quaternion

The general logic is simple

  1. From Euler angels, construct its rotation matrix.

  2. Convert rotation matrix to quaternion.