This section is divided into a number of subsections, links to which are:
This section demonstrates how to use quaternions for practical applications. You suppose to build intuition about how to use them as building blocks to solve engineering and geometry problems. Applications include computer graphics, attitude systems for air and spacecraft, biomechanics, and structural chemistry models. You may have read that quaternions have advantages over Euler angles to represent orientations, including preventing gimbal lock, and advantages over rotation matrices, such as more efficient computation, and compact form.
There are two conventions used in quaternion computations: The original one created by Hamilton, and one popularized by NASA's Jet Propulson Library (JPL). They sometimes go by the names Hamilton quaternions and JPL quaternions. The key difference between the two conventions lies in the relation between the three imaginary bases. In Hamilton convention, ijk = −1, while JPL defines ijk = 1. This section exclusively uses Hamilton quaternions.
Up until now we have learned that a rotation in ℝ³ about an axis through the origin can be represented by a 3 × 3 orthogonal matrix with determinant 1. However, the matrix representation seems redundant because only four of its nine elements are independent. Also the geometric interpretation of such a matrix is not clear until we carry out several steps of calculation to extract the rotation axis and angle. Furthermore, to compose two rotations, we need to compute the product of the two corresponding matrices, which requires twenty-seven multiplications and eighteen additions. It turns out that quaternions are very efficient in presenting rotations in ℝ³.
Quaternions
A legend is that in 1843, Hamilton was walking with his wife Helen at the Royal Irish Academy when he was suddenly struck by the idea of adding a fourth dimension in order to multiply triples. Excited by this breakthrough, as the couple passed the Broome Bridge of the Royal Canal, he carved the newfound theory of quaternions. You can recall a similar breakthrough of complex numbers discovery by the Italian mathematician and gambler Gerolamo Cardano (1501--1576), who achieved it when solving cubic equation.
As a vector space over ℝ, the quaternion space ℍ is 4-dimensional, which means that every its element is a 4-tuple: q = (q₀, q₁, q₂, q₃) with four real entries. However, ℍ is not isomorphic to ℝ4 because it has different algebraic structure. The quaternion number system admits multiplication between its elements and it is isomorphic to the direct sum ℝ⊕ℝ³. After many failed attempts, Hamilton finally came up with the idea of using three imaginary symbols i, j, and k that together with "1" form a basis in ℍ. Quaternions are generally represented in the form
Similar to the case of complex numbers, every quaternion is designated as
Then we define the following quantities.
Conjugate: q* = (𝑎 ; −u), where u = (b, c, d) ∈ ℝ³.
Modulus: \( \displaystyle \quad \| \mathbf{q} \| = \sqrt{a^2 + b^2 + c^2 + d^2} = \sqrt{a^2 + \left( \mathbf{w} \bullet \mathbf{w} \right)} = \sqrt{a^2 + \| {\bf w}\|^2} . \quad \)
Unit Quaternion: q = (𝑎, b, c, d) is said to be a unit quaternion if ∥q∥ = 1. A unit quaternion is also referred to as the rotation quaternion.
Since q q* = 𝑎² + b² + c² + d² is a nonnegative real number, we can define the modulus of q in ℍ by
Quaternions can be written in a matrix form, Since there are 48 distinct matrix representations of the same quaternion q = 𝑎 + bi + cj + dk, we present one of them:
Quaternion Multiplication
We define multiplication in ℍ using (1), the distributive law, and the usual rules of arithmetic in ℝ. Letting the chips fall where they may from there, we find that multiplication in ℍ is more exciting than multiplication in ℂ. For example, consider two quaternions q = (s, u) and p = (t, v):
Quaternion[a, b, c, d]
The formula for quaternion multiplication can be expressed somewhat succinctly in the following form (Sir Hamilton could not find a way to define multiplication):
A product of two quaternions is again a quaternion (which we write as a column):
P = {{p0, -p1, -p2, -p3}, {p1, p0, -p3, p2}, {p2, p3, p0, -p1}, {p3, -p2, p1, p0}};
Q1 = {{q0, q1, q2, q3}, {-q1, q0, q3, -q2}, {-q2, -q3, q0, q1}, {-q3, q2, -q1, q0}};
Simplify[Q1 . P . Q]/. p0 -> 0
Since ℍ is not a field, ℍ² is not a vector space. In treatments of matrix groups for mature audiences, though, matrices over ℍ are embraced as part of the family of linear operators. Though we will not delve into this, it is worth a moment to look at an actual 2 × 2 matrix over ℍ to see what transpires when our scalars come from ℍ.
Quaternion Multiplication and 3-d Rotations
So far, everything we have said about quaternions seems to be purely abstract algebraic manipulations. We will show that in fact, they provide a natural way to encode 3-dimensional rotations. First, let us define a multiplicative inverse for every nonzero quaternion:
Observe that if q is a unit quaternion---we consider only such quaternions---then it follows that q−1 = q*. As you might have guessed, our objective will be to show that there is a relation between rotating vectors and multiplying quaternions. In order to apply this insight, we need first to show how to represent rotations as quaternions and 3-dimensional vectors as quaternions.
Since quaternions provide a concise method of representing the automorphisms of three- and four-dimensional spaces, it becomes beneficial to use them in practical applications. Ken Shoemake was probably the first (1985) who discovered the connection between rotations and quaternions. For this reason, quaternions are used in computer graphics, control theory, robotics, signal processing, attitude control, physics, bioinformatics, and orbital mechanics. For example, it is common for spacecraft attitude-control systems to be commanded in terms of quaternions. Tomb Raider (1996) is often cited as the first mass-market computer game to have used quaternions to achieve smooth 3D rotation.
When we build a rotation in ℝ³, we need an angle Θ and the axis of rotation, which we specify by a unit vector along it, n = (nx, ny, nz) with \( \displaystyle \quad n_x^2 + n_y^2 + n_z^2 = 1 . \quad \) These four parameters (Θ and three components of n) uniquely identify both, a rotation by angle Θ along the axis n and the quaternion.
Let us consider a unit quaternion q = q₀ + u only. Then q0² + ‖u‖² = 1 implies that there must exist some angle θ such that
We know from an early reasoning that a is invariant under Lq. So let us focus on the effect of Lq on the orthogonal component n. We have \begin{align*} L_q (\mathbf{n}) &= \left( q_0^2 - \| \mathbf{u} \|^2 \right) {\bf n} + 2 \left( \mathbf{u} \bullet {\bf n} \right) \mathbf{u} + 2 q_0 \left( \mathbf{u} \times \mathbf{n} \right) \\ &= \left( q_0^2 - \| \mathbf{u} \|^2 \right) {\bf n} + 2 q_0 \left( \mathbf{u} \times \mathbf{n} \right) \\ &= \left( q_0^2 - \| \mathbf{u} \|^2 \right) {\bf n} + 2 q_0 \| \mathbf{u} \| \left( \mathbf{w} \times \mathbf{n} \right) , \end{align*} where in the last step above we introduced w = u/‖u‖. Denote n⊥ = w × n. So the last equation becomes \[ L_q (0; \mathbf{n}) = \left( q_0^2 - \| \mathbf{u} \|^2 \right) {\bf n} + 2 q_0 \| \mathbf{u} \| \,\mathbf{n}_{\perp} . \] Note that n⊥ and n have the same length: \[ \| \mathbf{n}_{\perp} \| = \| \mathbf{n} \times \mathbf{w} \| = \| \mathbf{n} \| \, \| \mathbf{w} \| \,\sin\frac{\pi}{2} = \| \mathbf{n} \| . \] Finally, we rewrite Lq(v) into the form \begin{align*} L_q (\mathbf{v} ) &= \left( \cos^2 \theta - \sin^2 \theta \right) \mathbf{n} + \left( 2\cos\theta\,\sin\theta \right) \mathbf{n}_{\perp} \\ &= \left( \cos\, 2\theta \right) \mathbf{n} + \left( \sin \,2\theta \right) \mathbf{n}_{\perp} . \end{align*} Namely, the resulting vector is a rotation of n through an angle 2θ in the plane defined by n and n⊥. See the figure below. This vector is clearly orthogonal to the rotation axis.
see page 5 of https://graphics.stanford.edu/courses/cs348a-17-winter/Papers/quaternion.pdf
We substitute the unit quaternion form q = q₀ + u into (3) to obtain the resulting vector from rotating a vector v about the axis u through 2θ: \begin{align*} L_q \left( \mathbf{v} \right) &= \left( \cos^2 \theta - \sin^2 \theta \right) \mathbf{v} + 2 \left( \mathbf{w}\,\sin\theta \bullet \mathbf{v} \right) \mathbf{w}\,\sin\theta + 2 \cos \theta \left( \mathbf{w}\,\sin\theta \times \mathbf{v} \right) \\ &= \cos (2\theta )\,\mathbf{v} + \left( 1 - \cos 2\theta \right) \left(\mathbf{w} \bullet \mathbf{v} \right) \mathbf{w} + \sin (2\theta ) \left( \mathbf{w} \times \mathbf{v} \right) . \end{align*}
Using formula (4), we obtain \begin{align*} L_q ({\bf j}) &= \mathbf{q} \left( 0; \mathbf{j} \right) \mathbf{q}^{\ast} \\ &= \end{align*} and \begin{align*} L_q ({\bf k}) &= \mathbf{q} \left( 0; \mathbf{j} \right) \mathbf{q}^{\ast} \\ &= \end{align*}
The unit vector u in the direction of the axis of rotation is \[ \mathbf{u} = \cos \left( \frac{\pi}{4} \right) {\bf i} + \sin \left( \frac{\pi}{4} \right) {\bf j} = \frac{1}{\sqrt{2}}\, {\bf i} + \frac{1}{\sqrt{2}}\, {\bf j} . \] To find the image of p = xi + yj + zk under the rotation, we calculate q p q*, where q is the quaternion \[ \mathbf{q} = \cos\theta + \sin\theta\,\mathbf{u} \] and θ is the half angle of rotation (30° in this case). The resulting quaternion—if we did the calculation right—would have no constant term and therefore we can interpret it as a vector. That vector gives us the answer.
We have \[ \mathbf{q} = \cos\left( \frac{\pi}{6} \right) + \sin \left( \frac{\pi}{6} \right) \mathbf{u} = \frac{\sqrt{3}}{2} + \frac{1}{2} \left( \frac{\sqrt{2}}{2}\,{\bf i} + \frac{\sqrt{2}}{2}\,{\bf j} \right) \] Since q is by construction a unit quaternion, its inverse is its conjugate: \( \displaystyle \quad \mathbf{q}^{-1} = {\bf q}^{\ast} = \frac{\sqrt{3}}{2} - \frac{\sqrt{2}}{4}\,{\bf i} - \frac{\sqrt{2}}{4}\,{\bf j} . \quad \) Now, computing qp in the routine way, we obtain \begin{align*} {\bf q}\,{\bf p} &= \left( \frac{\sqrt{3}}{2} + \frac{\sqrt{2}}{4}\,{\bf i} + \frac{\sqrt{2}}{4}\,{\bf j} \right) \left( x{\bf i} + y{\bf j} + z{\bf k} \right) \\ &= x \left( \frac{\sqrt{3}}{2}\,{\bf i} - \frac{\sqrt{2}}{4} - \frac{\sqrt{2}}{4}\,{\bf k} \right) + y \left( - \frac{\sqrt{2}}{4} + \frac{\sqrt{3}}{2}\,{\bf j} + \frac{\sqrt{2}}{4}\,{\bf k} \right) \\ & \quad + z \left( \frac{\sqrt{3}}{2}\,{\bf k} - \frac{\sqrt{2}}{4}\,{\bf j} + \frac{\sqrt{2}}{4}\,{\bf i} \right) . \end{align*} Then another long but routine computation give \begin{align*} {\bf q}\,{\bf p}\,{\bf q}^{\ast} &= x \left( - \frac{\sqrt{2}}{4} + \frac{\sqrt{3}}{2}\,{\bf i} - \frac{\sqrt{2}}{4}\,{\bf k} \right) \left( \frac{\sqrt{3}}{2} - \frac{\sqrt{2}}{4}\,{\bf i} - \frac{\sqrt{2}}{4}\,{\bf j} \right) \\ & \quad + y \left( - \frac{\sqrt{2}}{4} + \frac{\sqrt{3}}{2}\,{\bf j} + \frac{\sqrt{2}}{4}\,{\bf k} \right) \left( \frac{\sqrt{3}}{2} - \frac{\sqrt{2}}{4}\,{\bf i} - \frac{\sqrt{2}}{4}\,{\bf j} \right) \\ & \quad + z \left( \frac{\sqrt{3}}{2}\,{\bf k} - \frac{\sqrt{2}}{4}\,{\bf j} + \frac{\sqrt{2}}{4}\,{\bf i} \right) \left( \frac{\sqrt{3}}{2} - \frac{\sqrt{2}}{4}\,{\bf i} - \frac{\sqrt{2}}{4}\,{\bf j} \right) \\ &= x \left( \frac{\sqrt{6}}{8} - \frac{\sqrt{6}}{8} + \frac{1}{8}\,{\bf i} + \frac{1}{8}\,{\bf j} + \frac{3}{4}\,{\bf i} - \frac{\sqrt{6}}{8}\,{\bf k} + \frac{1}{8}\,{\bf j} \right) \end{align*}
Given a unit quaternion q = [q₀, q₁, q₂, q₃] = q₀ + q₁i + q₂j + q₃k with ∥q∥ = 1, the corresponding passive rotation matrix is
The quaternion operator Lq*(v) = q*(0; v)q may be interpreted as a coordinate frame rotation with respect to the (fixed) space of points. Equivalently, the operator Lq* actively rotates the vector v with respect to the coordinate frame through an angle −θ about u. The quaternion operator Lq(v) = q(0; v)q* may be interpreted as a point or vector rotation with respect to the (fixed) coordinate frame.
Let us consider the rotation around an axis n = (nx, ny, nz) by an angle 2𝜃, represented by a quaternion:
Properties of Quaternion
The set of all quaternions is denoted by ℍ and its subset of all unit (rotation) quaternions is denoted by U(1, ℍ). This group is isomorphic to the special unitary group:
The following are some useful properties of quaternions. Up until now, we discussed only rotation quaternions (of unit length), denoted by U(1, ℍ). However, rotation quaternions are only a subset of all possible quaternions, just as rotation matrices are a subset of all possible 3x3 matrices. The following properties apply to all quaternions q = (q₀, q₁, q₂, q₃) ∈ ℍ unless otherwise specified.
- The length (magnitude) of a quaternion is its norm: ∥q∥ = \( \displaystyle \sqrt{\mathbf{q}\,\mathbf{q}^{\ast}} = \sqrt{\mathbf{q}^{\ast}\mathbf{q}} = \sqrt{q_0^2 + q_1^2 + q_2^2 + 1_3^2} . \)
- A quaternion is called a "unit" quaternion if ∥q∥ = 1.
- All rotation quaternions must be of unit norm.
- The quaternion q = (1, 0, 0, 0) is the identity quaternion, which we denote by 1. It represents no rotation. If q is an arbitrary quaternion and 1 is the identity quaternion, then q 1 = 1 q = q.
- The conjugate of a quaternion q = (q₀, q₁, q₂, q₃) is q* = (q₀, −q₁, −q₂, −q₃). Also q*)* = q.
- The inverse of a quaternion q = (q₀, q₁, q₂, q₃) is \( \displaystyle \mathbf{1}^{-1} = \frac{1}{\| {\bf q} \|}\,\mathbf{q}^{\ast} . \) The product of a quaternion and its inverse is the identity quaternion: \( \displaystyle \mathbf{q}^{-1} \mathbf{q} = \mathbf{q} \,{\bf q}^{-1} = \mathbf{1} = (1, 0, 0, 0, 0) . \) Note that for this special case, quaternion multiplication is commutative.
- For rotation quaternions q ∈ U(1, ℍ), the inverse equals the conjugate. So for rotation quaternions, \( \displaystyle \mathbf{q}^{-1} = \mathbf{q}^{\ast} = (1, 0, 0, 0). \)
- Inverting or conjugating a rotation quaternion has the effect of reversing the axis of rotation, which modifies it to rotate in the opposite direction from the original. That is, if a point is rotated to a new position using q, then rotating it again using q−1 or q* will return it to its original location.
- Any given rotation has two possible quaternion representations. If one is known, the other can be found by taking the negative of all four terms. This has the effect of reversing both the rotation angle and the axis of rotation. So if q is a rotation quaternion, then q and −q will produce the same rotation.
- A rotation of qa followed by a rotation of qb can be combined into the single rotation qc = qbqa. This can be extended to an arbitrary number of rotations. Note that the order matters (because quaternion multiplication is not commutative).
- Quaternion multiplication is associative: (ab)c = a(bc).
- Generally speaking, quaternion multiplication is not commutative: ab ≠ ba.
From a matrix of angles to a quaternion
Given a rotation matrix R, we can compute the quaternion that represents the same rotation. First, we compute the trace, the sum of the elements on the main diagonal of the matrix:To resolve the signs, find the largest of q₀, q₁q1, q₂, q₃ and assume its sign is positive. Then compute the remaining components as shown in the table below. Taking the largest magnitude avoids division by small numbers, which would reduce numerical accuracy.
If q₀ is largest: | If q₁ is largest: | If q₂ is largest: | If q₃ is largest: |
\( \displaystyle \quad q_1 = \frac{r_{3,2} - r_{2,3}}{4\,q_0} \quad\) | \( \displaystyle \quad q_0 = \frac{r_{3,2} - r_{2,3}}{4\,q_1} \quad\) | \( \displaystyle \quad q_0 = \frac{r_{1,3} - r_{3,1}}{4\,q_2} \quad\) | \( \displaystyle \quad q_1 = \frac{r_{2,1} - r_{1,2}}{4\,q_3} \quad\) |
\( \displaystyle \quad q_2 = \frac{r_{1,3} - r_{3,1}}{4\,q_0} \quad\) | \( \displaystyle \quad q_2 = \frac{r_{2,1} + r_{1,2}}{4\,q_1} \quad\) | \( \displaystyle \quad q_1 = \frac{r_{1,3} + r_{3,1}}{4\,q_2} \quad\) | \( \displaystyle \quad q_1 = \frac{r_{1,3} + r_{3,1}}{4\,q_3} \quad\) |
\( \displaystyle \quad q_3 = \frac{r_{2,1} - r_{1,2}}{4\,q_0} \quad\) | \( \displaystyle \quad q_3 = \frac{r_{1,3} + r_{3,1}}{4\,q_1} \quad\) | \( \displaystyle \quad q_3 = \frac{r_{2,3} + r_{3,2}}{4\,q_2} \quad\) | \( \displaystyle \quad q_2 = \frac{r_{2,3} + r_{3,2}}{4\,q_3} \quad\) |
From Euler angles to a quaternion
Given a rotation by an angle, the corresponding quaternion can be computed. Consider the rotation ψ around the z-axis:Now suppose that we know three Euler angles, ϕ, θ, and ψ. We can convert from Euler's angles to quaternion q = (q₀, q₁, q₂, q₃) as follows:
θ = pitch angle,
ψ = yaw angle,
c() = cosine function,
s() = sine function.
These equations work for all values of Euler angle, including the condition of gimbal lock, where the pitch angle equals +90° or −90°.
Convert Quaternion to Euler Angles
The previous subsection allows us to determine Euler's angles from quaternions:Quaternions and Rotations by Yan-Bin Jia.
An important problem in model-based recognition is to find the transformation of a set of data points that yields the best match of these points against a shape model. The process is often referred to as data registration. The data points are typically measured on a real object by range sensors, touch sensors, etc., and given in Cartesian coordinates. The quality of a match is often described as the total squared distance from the data points to the model. When multiple shape models are possible, the one that results in the least total distance is then recognized as the shape of the object.
Quaternions are very effective in solving the above least-squares-based registration problem. Let us begin with a formulation of the problem in 3D. Let {p₁, p₂, … , pn} be a set of data points. We assume that p₁, p₂, … , pn are to be matched against the points q₁, q₂, … , qn on a shape model. Namely, the correspondences between the data points and those on the model have been predetermined. Then the problem is to find a rotation, represented by an orthogonal matrix R with det(R) = 1, and a translation b as the solution to the following minimization: \[ \min_{{\bf R}, {\bf b}} \sum_{i=1}^n \| {\bf R}\,{\bf p}_i +{\bf b} - {\bf q}_i \|^2 . \tag{9.1} \] We begin by computing the centroids of the two sets of points: \begin{align*} \overline{\bf p} &= \frac{1}{n} \sum_{i=1}^n {\bf p}_i , \\ \overline{\bf q} &= \frac{1}{n} \sum_{i=1}^n {\bf q}_i . \end{align*} The relative coordinates of all the points to their centroids are obtained as, for 1 ≤ i ≤ n, \begin{align*} {\bf p}'_i &= {\bf p}_i - \overline{\bf p} , \\ {\bf q}'_i &= {\bf q}_i - \overline{\bf q} . \end{align*} Clearly, we have \begin{align*} \sum_{i=1}^n {\bf p}'_i &= \sum_{i=1}^n {\bf p}_i - n\,\overline{\bf p} = \sum_{i=1}^n {\bf p}_i - n\cdot \frac{1}{n} \sum_{i=1}^n {\bf p}_i = {\bf 0}, \\ \sum_{i=1}^n {\bf q}'_i &= \sum_{i=1}^n {\bf q}_i - n\,\overline{\bf q} = \sum_{i=1}^n {\bf q}_i - n\cdot \frac{1}{n} \sum_{i=1}^n {\bf q}_i = {\bf 0} . \end{align*} Let us rewrite the objective function in (9.1) in terms of data \begin{align*} I &= \sum_{i=1}^n \| {\bf R}\,{\bf p}_i +{\bf b} - {\bf q}_i \|^2 \\ &= \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i + {\bf R}\,\overline{\bf p} + {\bf b} - \overline{\bf q} \|^2 \\ &= \sum_{i=1}^n \left( {\bf R}\,{\bf p}'_i - {\bf q}'_i + {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \right) \bullet \left( {\bf R}\,{\bf p}'_i - {\bf q}'_i + {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \right) \\ &= \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i \|^2 + \left( 2 \sum_{i=1}^n \left( {\bf R}\,{\bf p}'_i - {\bf q}'_i \right) \right) \bullet \left( {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \right) + n \| {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \|^2 \\ &= \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i \|^2 + 2 \left( {\bf R} \sum_{i=1}^n {\bf p}'_i - \sum_{i=1}^n {\bf q}'_i \right) \bullet \left( {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \right) + n \| {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \|^2 \\ &= \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i \|^2 + n \| {\bf R}\,\overline{\bf p} - \overline{\bf q} + {\bf b} \|^2 \end{align*} The minimizing translation b should make the second term in the last equation above zero, yielding: \[ \mathbf{b} = \overline{\bf q} - {\bf R}\,\overline{\bg p} . \tag{9.2} \] Thus, we have decomposed the problem of data registration into two phases: the first of which determines its optimal translation, as given by equation (9.2), and the second of which determines the optimal rotation of the set {pi}. Note that every point pi is transformed into R(pi \( \displaystyle - \overline{\bf p}) + \overline{\bf q} \quad \) before matching against qi. Equivalently, to find the best match of the two point sets {pi} and {qi}, we first translate {pi} to let their centroid coincide with that of {qi}, and then rotate about the common centroid.
By the reasoning so far, the optimal rotation can be solved from the formulation below: \[ \min_{R} \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i \|^2 . \tag{9.3} \] Here we present an exact solution to (9.3) as described in [B. K. P. Horn. Closed-form solution of absolute orientation using unit quaternions. Journal of Optical Society of America A, 4(4):629–642, 1987.] using quaternions. An equivalent quaternion-based solution is given in [O. D. Faugeras and M. Hebert. The representation, recognition, and locating of 3-D objects. International Journal of Robotics Research, 5(3):27–52, 1986.]. The version of matching two curves (or surfaces), also assuming pointwise correspondences, is solved exactly in [J. T. Schwartz and M. Sharir. Identification of partially obscured objects in two and three dimensions by matching noisy characteristic curves. International Journal of Robotics Research, 6(2):29–44, 1987.] in a somewhat similar manner without the use of quaternions.
First, we rewrite the summation in (9.3) as follows \begin{align*} \sum_{i=1}^n \| {\bf R}\,{\bf p}'_i - {\bf q}'_i \|^2 &= \sum_{i=1}^n \left( {\bf R}\,{\bf p}'_i \bullet {\bf R}\,{\bf p}'_i \right) -2 \sum_{i=1}^n \left( {\bf R}\,{\bf p}'_i \bullet {\bf q}'_i \right) + \sum_{i=1}^n {\bf q}'_i \bullet {\bf q}'_i \\ &= \sum_{i=1}^n \left( \| {\bf p}'_i \|^2 + \| {\bf q}'_i \|^2 \right) -2 \sum_{i=1}^n {\bf R}\,{\bf p}'_i \bullet {\bf q}'_i . \end{align*} The first summand in the last equation above does not depend on the rotation, so we need only minimize the second summand. Equivalently, this can be done through a maximization: \[ \max_{R} \sum_{i=1}^n {\bf R}\,{\bf p}'_i \bullet {\bf q}'_i . \] The rotation matrix R has nine entries, only four of which are independent due to the orthogonality and unit determinant of R. Instead, we represent rotations using unit quaternions. Essentially, we find the unit quaternion q that maximizes \[ \sum_{i=1}^n \left( {\bf q}\,{\bf p}'_i {\bf q}^{\ast} \right)\bullet {\bf q}'_i . \tag{9.4} \] Here we view quaternions as vectors in ℝ4. Let q = (q₀, q₁, q₂, q₃)T and q* = (q₀, −q₁, −q₂, −q₃)T. Also, the points p′₁, … , p'n and q′₁, … , q'n are viewed as 4-tuples with p′i = (0; pi1, pi2, pi3)T and q′i = (0; qi1, qi2, qi3)T by a slight abuse of notation.
Applying the definition of quaternion product, it is not difficult to show that \[ \left( {\bf q}\,{\bf p}'_i {\bf q}^{\ast} \right)\bullet {\bf q}'_i = \left( {\bf q}\,{\bf p}'_i \right) \bullet \left( {\bf q}'_i {\bf q} \right) . \tag{9.5} \] Next, we intend to rewrite the summands in (9.4) as matrix products. For this purpose, we define matrices \[ {\bf P}_i = \begin{bmatrix} 0& -p'_{i1} & -p'_{i2} & -p'_{i3} \\ p'_{i1} & 0 & p'_{i3} & -p'_{i2} \\ p'_{i2} & -p'_{i3} & 0 & p'_{i1} \\ p'_{i3} & p'_{i2} & -p'_{i1} & 0 \end{bmatrix} \quad\mbox{and}\quad {\bf Q}_i = \begin{bmatrix} 0 & -1'_{i1} & -q'_{i2} & -q'_{i3} \\ q'_{i1} & 0 & -q'_{i3} & q'_{i2} \\ q'_{i2} & q'_{i3} & 0 & -q'_{i1} \\ q'_{i3} & -q'_{i2} & q'_{i1} & 0 \end{bmatrix} \] For 1 ≤ i ≤ n. Then the quaternion products qp′i and q′iq are equivalent to the matrix products Piq and Qiq. We thus have \begin{align*} \sum_{i=1}^n \left( {\bf q}\,{\bf p}'_i {\bf q}^{\ast} \right)\bullet {\bf q}'_i &= \sum_{i=1}^n \left( {\bf q}\,{\bf p}'_i \right) \bullet \left( {\bf q}'_{i} {\bf q} \right) \\ &= \sum_{i=1}^n \left( {\bf P}_i {\bf q} \right) \bullet \left( {\bf Q}_i {\bf q} \right) \\ &= \sum_{i=1}^n {\bf q}^{\mathrm T} {\bf P}^{\mathrm T}_i {\bf Q}_i {\bf q} \\ &= {\bf q}^{\mathrm T} \left( {\bf P}^{\mathrm T}_i {\bf Q}_i \right) {\bf q} . \end{align*} It is easy to verify that each matrix PTiQi is symmetric, so is the 4 × 4 matrix \[ \mathbf{M} = \sum_{i=1}^n {\bf P}^{\mathrm T}_i {\bf Q}_i . \] Thus, M has real eigenvalues only, say, λ₁, λ₂, λ₃, λ₄ with λ₁ ≥ λ₂ ≥ λ₃ ≥ λ₄. Let v₁, v₂, v₃, v₄ be the corresponding orthogonal unit eigenvectors. Eigenvectors corresponding to different eigenval- ues must be orthogonal to each other. Multiple eigenvectors corresponding to the same eigenvalue are chosen to be orthogonal to each other. The quaternion q is a linear combination of these eigenvectors: \[ \mathbf{q} = \alpha_1 {\bf v}_1 + \alpha_2 {\bf v}_2 + \alpha_3 {\bf v}_3 + \alpha_4 {\bf v}_4 . \] Therefore, we have \begin{align*} \mathbf{q}^{\mathrm T} \mathbf{M}\,{\bf q} &= \left( \alpha_1 {\bf v}_1 + \alpha_2 {\bf v}_2 + \alpha_3 {\bf v}_3 + \alpha_4 {\bf v}_4 \right)^{\mathrm T} \left( \alpha_1 {\bf v}_1 + \alpha_2 {\bf v}_2 + \alpha_3 {\bf v}_3 + \alpha_4 {\bf v}_4 \right) \\ &= \left( \alpha_1 {\bf v}_1 + \alpha_2 {\bf v}_2 + \alpha_3 {\bf v}_3 + \alpha_4 {\bf v}_4 \right) \bullet \left( \lambda_1\alpha_1 {\bf v}_1 + \lambda_1 \alpha_2 {\bf v}_2 + \lambda_3 \alpha_3 {\bf v}_3 + \lambda_4 \alpha_4 {\bf v}_4 \right) \\ &= \lambda_1 \alpha_1^2 + \lambda_2 \alpha_2^2 + \lambda_3 \alpha_3^2 + \lambda_4 \alpha_4^2 . \end{align*} The product qTM q achieves its maximum when α₁ = 1 and α₂ = α₃ = α₄ = 0. Therefore, the unit quaternion q that maximizes (14) is the eigenvector that corresponds to the largest eigenvalue of the matrix M. It describes the optimal rotation for (12), i.e, for data registration.
When the corresponding points q1, … , qn are unknown, a well-known method called the Iterative Closest Point (ICP) [P. J. Besl and N. D. McKay. A method for registration of 3-D shapes. IEEE Transactions on pattern analysis and machine intelligence, 14(2):239–256, 1992.] solves the registration problem. Given a set of data points {p₁, … , pn}, the ICP algorithm finds the initial corresponding points q(0)1, … , q(0)n as the closest points on the surface model to p(0)1 = p₁, … , p(0)n = pn, respectively. Then it applies the introduced quaternion- based method to determine the rotation and translation that best match {p(0)n} with {q(0)i}. The second iteration applies the just found transformation to every p(0)i, obtaining p(1)i p(1) i , and then determines its new corresponding point q(1)i on the model as the closest point to p(1)i. Recompute the best rotation and translation using quaternions, and so on. The algorithm stops when the change in the new transformation becomes small enough. ■
- Altmann, S.L., Rotations, Quaternions, and Double Groups, Dover Publications; Illustrated edition (November 3, 2005)
- Altmann, S.L., Hamilton, Rodrigues, and the quaternion scandal, Mathematics Magazine 62(5) 291–308 (1989).
- Bickford, N., Why Do the Unit Quaternions Double-Cover the Space of Rotations?
- ten Bosch, M., Let's remove Quaternions from every 3D Engine,
- Conway, J.H., On Quaternions and Octonions: Their Geometry, Arithmetic, and Symmetry, A K Peters/CRC Press; 1st edition (January 23, 2003)
- Dai, J.S., Euler–Rodrigues formula variations, quaternion conjugation and intrinsic connections, Mechanism and Machine Theory, 2015, pp. 144--152.
- Dunn, F. and Parberry, I. (2002). 3D math primer for graphics and game development. Plano, Tex.: Wordware Pub.
- Foley, James D.; van Dam, Andries; Feiner, Steven K.; Hughes, John F. (1991), Computer Graphics: Principles and Practice (2nd ed.), Reading: Addison-Wesley, ISBN 0-201-12110-7
- Hanson, A.J., Visualizing Quaternions: Belt-Trick Documentation, Indiana University.
- Hamilton, W. R., On a new species of imaginary quantities connected with a theory of quaternions, Proceedings of the Royal Irish Academy 2 424-434 (1844).
- Hanson, A.J., Visualizing Quaternions (The Morgan Kaufmann Series in Interactive 3D Technology) 1st Edition, 2006.
- Kuipers, J.B., Quaternions and Rotation Sequences. Princeton University Press, 1999.
- Matrices and Linear Transformations
- Pujol, J., Hamilton, Rodrigues, Gauss, quaternions, and rotations: A historical reassessment, Communications in Mathematical Analysis 13(2) 1-14 (2012).
- Rogers, D.F., Adams, J. A., Mathematical Elements for Computer Graphics, McGraw-Hill Science/Engineering/Math, 1989.
- Sanderson, G., Visualizing quaternionsquaternions, Technology by Ben Eater.
- Shoemake, K., Animating Rotation with Quaternion Curves, San Francisco. Ju;y 22--26, ACM, vol. 19, N.3, 1985.
- Watt, A., 3D Computer Graphics, Addison-Wesley; 3rd edition, 1999.