During my thesis, I researched different techniques for estimating the orientation of an object in a three-dimensional space. Think of your head, you can tilt left/right, look up/down, or right/left. Well, the exact position of your head can be expressed mathematically and quaternions are one of the options.
Quaternions were introduced by Hamilton (1843) and are used to represent the attitude of a rigid body in space. They can be viewed as an extension of complex numbers. A complex number can be used to represent the rotation in a two-dimensional space. A quaternion is similar, but instead of one axis it is extended to three axes. For its representation, four values are needed, where there is one real component q0 and three imaginary q1,q2,q3 ones:
q=q0+q1i+q2j+q3k
It is also represented as a vector matrix q, where q1,q2,q3 are multiplied by i,j,k respectively.
q=[q0q1q2q3]t
The quaternion that represents a rotation of θ degrees around an axis defined by the vector n=[nxnynz] is given by:
q=[nxinyjnzk]sin(θ/2)+cos(θ/2)
This means that a rotation of θ=π/2 around the axis n=[100] will correspond to a quaternion given by the following expression.
q=[222200]
A quaternion is often represented as a normalized vector. It can be normalized using the following expression, where ∣q∣ can be calculated as follows.
qnorm=∣∣q∣∣q∣∣q∣∣=q02+q12+q22+q32
Different operations can be done with quaternions. Adding two quaternions qa+qb can be done by adding each element of the vector. Multiplying by a scalar, is done by multiplying the scalar by each element, like if it were a simple two or three-dimensional vector. One of the most important operations is the product.
Let (a1+b1i+c1j+d1k) be the qa quaternion and (a2+b2i+c2j+d2k) the second quaternion qb. They can be multiplied qaqb by using the Hamilton product which is given by the following expression. Note that the product does not have the commutative property, so qaqb is not the same as qbqa.
The following expression determine all the possible combinations of i,j,k multiplications, so for example k=ij or ji=−k
i2=j2=k2=ijk=−1
Quaternions have a very interesting property, the Hamilton product, because it can combine two rotations into only one. For example in the previous quaternion, which represents a rotation of θ=π/2 in the axis n=[100] is used two times, the result rotation will be θ=π in the same axis. Doing the maths, the Hamilton product of that quaternion multiplied with itself, yields:
q=[0100]
Which is the same as substituting θ=π and n=[100]. Both results are the same.
Since there are different ways of representing the attitude of a body in the space, it is important to know how to change between different representations. For example, the ZYX or 3,2,1 conversion conversion matrices are given. Using the following Euler angles θ1,θ2,θ3 can be converted to the quaternion representation.