A blog for aerospace science and technologies

Quaternions and attitude representation

Complex numbers are very convenient for describing planar rotations. For example, any complex number z = a+ib multiplied by i is rotated by 90 degrees counterclockwise as:

iz = e^{i 90} \rho e^{i\theta} = \rho e^{i(\theta+90)}

A 2d rotation only needs one degree of freedom, the rotation angle, and a constraint that ensures that the rotation does not change space in length but only rotates it, which is obtained by normalizing the complex number.

Fig. 1: Example of complex number rotations

For what concerns 3d space, three degrees of freedom are needed, plus the unit constraint; thus four variables, of which only three are truly independent, can be used to represent a rotation.

Quaternions

Quaternions have been originally described by William Rowan Hamilton in 1843 as an extension of complex numbers. A quaternion is written as:

q = a + bi + cj + dk

where i, j and k are imaginary numbers and a, b, c, d are real ones. a is also referred to as the scalar part while bi + cj + dk is the vector part.

The four components of a quaternion can be multiplied together and represent, as the imaginary unit i in complex numbers, 90 degrees rotations around a unitary versor of a 4d reference frame. Moreover, the order of multiplication between these quantities is fundamental: for example, ij=k but ji=-k.

Fig. 2: Example of various 90 degrees rotations in a 4d reference frame

An important mathematical operation between quaternions is the Hamilton product, usually denoted with \odot, which is used to multiply two quaternions as:

q_1 \odot q_2 = (r_1,v_1) \odot (r_2,v_2) = (r_1r_2-v_1 \cdot v_2,r_1v_2+r_2v_1+v_1 \times v_2)

where r_i represents the i-th quaternion scalar part while v_i is the corresponding vector part.

Quaternions for attitude representation

With respect to attitude representation, a quaternion is reorganized by placing the vector part first and the scalar part last as:

\bm{q}= \left[\begin{array}{c} \bm{\epsilon} \\ \eta\end{array}\right]

Even though quaternions have four independent components, for what concerns 3d rotations, the unit quaternion constraint must be added, thus reducing the number of independent variables to three. This constraint is set by imposing || \bm{q} || = 1 , or

\sqrt{\epsilon_1 ^2 + \epsilon _2 ^2 + \epsilon _3 ^2 + \eta^2} = 1

The Hamiltonian product with this notation becomes:

\bm{q_1} \odot \bm{q_2} = ( \bm{\epsilon_1} ,\eta_1) \odot ( \bm{\epsilon_2} ,\eta_2) = \left[ \begin{array}{c}\eta_1 \bm{\epsilon_2}+ \eta_2 \bm{\epsilon_1} + \bm{\epsilon_1} \times \bm{\epsilon_2} \\ \eta_1\eta_2- \bm{\epsilon_1} \cdot \bm{\epsilon_2}\end{array}\right]

Sometimes it can be useful to express the Hamilton product using simple matrix products. By recalling that

\bm{a}\times\bm{b} = \left(\begin{array}{c} a_2 b_3-a_3 b_2 \\ a_3 b_1-a_1 b_3 \\ a_1 b_2-a_2 b_1\end{array}\right) = \left[\begin{array}{ccc}0 & -a_3 & a_2 \\ a_3 & 0 & -a_1 \\-a_2 & a_1 & 0 \end{array}\right] \left(\begin{array}{c} b_1 \\ b_2 \\ b_3 \end{array}\right)= [\bm{a}]^\times\bm{b}

the Hamilton product can be expressed as:

\bm{q_1}\odot \bm{q_2} = \left[ \begin{array}{cc} \eta I_{3,3} + [\bm{\epsilon}]^\times & \bm{\epsilon} \\ -\bm{\epsilon}^T & \eta \end{array}\right] \bm{q_2} = \left[\begin{array}{cc}\bm{\Xi}(\bm{q_1})&\bm{q_1}\end{array}\right] \bm{q_2}

A useful product for attitude representation is the quaternion cross product, which is very similar to the Hamilton product:

\bm{q_1}\otimes \bm{q_2} = \bm{q_2}\odot \bm{q_1}

\bm{q_1}\otimes \bm{q_2} = \left[ \begin{array}{cc} \eta I_{3,3} - [\bm{\epsilon}]^\times & \bm{\epsilon} \\ -\bm{\epsilon}^T & \eta \end{array}\right] \bm{q_2} = \left[\begin{array}{cc}\bm{\Psi}(\bm{q_1})&\bm{q_1}\end{array}\right] \bm{q_2}

By using the cross product, a rotation of a generic point \bm{x} is obtained by multiplying quaternion \bm{q} and \bm{q}^{-1} as:

f(p) = \bm{q} \otimes \bm{x} \otimes \bm{q}^{-1} = \left[\begin{array}{c} \bm{\Xi}^T(\bm{q}) \bm{\Psi}(\bm{q}) \bm{x} \\ 0 \end{array}\right] = \left[\begin{array}{c} \bm{A}(\bm{q})\bm{x} \\ 0 \end{array}\right]

where \otimes is the cross product and \bm{q} ^{-1} is the inverse of quaternion \bm{q} (same scalar part, negative vector part). A double multiplication involving \bm{q} and \bm{q} ^{-1} is needed to ensure that the rotation does not deform lengths in space. Moreover, the rotation matrix can be obtained from a quaternion \bm{q} as:

\bm{C}_{ab} = (\eta^2-\bm{\epsilon}^T\bm{\epsilon})\bm{I}_{3,3}+2\bm{\epsilon}\bm{\epsilon}^T-2\eta[\bm{\epsilon}]^\times

Finally, to concatenate successive rotations, it holds that

\bm{q_2} \otimes ( \bm{q_1} \otimes \bm{x} \otimes \bm{q_1}^{-1} ) \otimes \bm{q_2}^{-1} = \left[\begin{array}{c} \bm{A}(\bm{q_2} \otimes \bm{q_1})\bm{x} \\ 0 \end{array}\right] = \left[\begin{array}{c} \bm{A}(\bm{q_2}) \bm{A}(\bm{q_1}) \bm{x} \\ 0 \end{array}\right]

Conclusions

As previously stated, quaternions are not an intuitive object intrinsically because of their 4d nature, which we sadly cannot experience; an in-depth overview on quaternions as 4d objects is provided in Ref. [1]. However, quaternions are directly related to Euler Axis/Angle attitude representation, which gives a more intuitive view of their rotating action:

\bm{q} = \left[\begin{array}{c}e_x \sin( \frac{\phi}{2} )\\ e_y \sin( \frac{\phi}{2} ) \\ e_z \sin(\frac{\phi}{2}) \\ \cos( \frac{\phi}{2} ) \end{array}\right]

where \bm{e} is Euler Axis and \phi is Euler Angle. This makes it easier to quickly understand what a quaternion does by directly deriving the rotation axis and the rotation angle in 3d space. In addition, as previously stated, a quaternion \bm{q} is responsible only for half of the rotation angle, as the other half is achieved by its inverse \bm{q}^{-1} .

Another inconvenience of quaternions is that two quaternions \bm{q} and -\bm{q} in 4d are mapped to the same rotation in 3d. Quaternions double-cover the space of 3d rotations and this is more easily understood when looking at the Euler axis/angle representation. Two different Euler angles can be exploited to get to a given attitude:

Fig. 3: Example of two rotations that result in the same final attitude

Quaternions are however a powerful tool in attitude representation for many reasons. Indeed, they do not have singularities and do not suffer from the gimbal lock problem, differently from Euler angles. Their algebra is efficient, as the rotation matrix is constructed using a quadratic equation with no trigonometric functions, an important aspect for embedded systems. Finally, they allow for easy interpolation between two different attitudes, which could lead to gimbal lock when using Euler Angles representation or expensive computations when using Euler Axis/Angle representation.

References

[1] Grant Sanderson, Ben Eater, “Visualizing quaternions”

[2] F. Landis Markley, John L. Crassidis, “Fundamentals of Spacecraft Attitude, Determination and Control”

[3] Steve Ulrich, “AERO4540 – Spacecraft Attitude Dynamics and Control – Lecture 2”

[4] Quaternions, Wikiwand

Post Image Credits: Wikipedia, the free encyclopedia

Share on facebook
Share on twitter
Share on linkedin

Related Articles