Quaternion Quick Facts¶
This is not meant to be a treatise on quaternions, but a summary relevant for the code implementation. It also assumes familiarity with linear algebra.
See also the Matrix and Quaternions FAQ for a practical compendium of equations for implementing matrix and quaternion operations.
Quaternions¶
The space of quaternions is a vector space generated by the basis
A multiplication operation is defined over the space such that:
it is distributive with respect to the usual sum
the identity is the element
the products of the basis elements is given by
:
Example: The product of two pure vectors
Rotations¶
Most often, 3-d rotations are represented as
Some properties of rotations:
they are orthogonal:
ordet(M) = 1
In what follows we use the following elemental (right-handed) rotations of
Angle-axis Representation¶
A 3-d rotation can be uniquely defined by a unit vector and an angle
there is one and only one real-valued eigenvalue:
.the rotation axis is given by a unit eigenvector of M with eigenvalue
.the rotation angle is given by the trace of M:
.
Equatorial Representation¶
Any rotation can be decomposed as a sequence of three rotations around different cartesian axes.
Using the equatorial coordinates related to a fixed intertial reference frame, this can be expressed as
Quaternion Representation¶
A rotation can be represented by a quaternion operator:
where
Switching Representations¶
Equatorial -> Matrix¶
Let’s write
Matrix -> Equatorial¶
From Eq. (6) we can invert and get:
Quaternion -> Matrix¶
Expanding Eq. (4) using the multiplication rules in Eq. (1), and then grouping factors of
For practical reasons, some times we want to express the transform in terms of a quaternion with norm
Matrix -> Quaternion¶
This is a bit more involved. The idea is to invert from Eq. (8). From the diagonal elements we can already get the squares of the quaternion components:
The next step depends on which entry in Eq. (9) is the largest:
Note that the denominator is always
Derivation. As an example, we derive one of the cases in Eq. (10). The rest are similar.
The idea is to scale the quaternion so its largest component is equal to 1. In other words, if the i-th entry in
Eq. (9) is the largest, then multiply q by a factor
If
and we can set:
and after normalizing:
Equatorial -> Quaternion¶
This code first transforms from equatorial to matrix, and then from matrix to quaternion.
Quaternion -> Equatorial¶
Transform from quaternion to matrix, and then from matrix to equatorial.