1

Quaternion Computation Neil Dantam [email protected] Institute for Robotics and Intelligent Machines, Georgia Institute of Technology, Atlanta, GA, USA

Work in Progress – Updated 2014-10-01. IV-F Conjugate...... 6 IV-G Exponential...... 6 Abstract— are a useful representation for orienta- tion, and dual quaternions extend the representation to handle IV-H Logarithm...... 7 translations as well. This report discusses computations that can IV-I Chaining Transforms...... 7 be performed using quaternions. To accurately compute results IV-J Transforming a point...... 7 near singularities, we provide Taylor series approximations which can be efficiently computed to within machine precision. IV-K Derivatives...... 7 IV-K1 Product Rule...... 7 IV-K2 Angular Velocity...... 7 CONTENTS IV-K3 Translational Velocity....7 I Introduction 1 IV-L Integration...... 7 I-A Notation...... 2 V Implicit Dual Quaternions 7 II Quaternions 2 V-A Chaining transforms...... 7 II-A Representation...... 2 V-B Transforming points...... 8 II-B Multiplication...... 2 V-C Conjugate...... 8 II-B1 Cross and dot product defi- V-D Derivatives...... 8 nition...... 2 II-B2 Matrix definition...... 2 VI Matrices and Euclidean Transforms 8 II-B3 Properties...... 3 VI-A Rotation Matrix...... 8 II-B4 Pure Multiplication.....3 VI-B Transformation Matrix...... 8 II-C Norm...... 3 VI-C Transforming Points...... 8 II-D Conjugate...... 3 II-E Inverse...... 3 VI-D Chaining Transforms...... 8 II-F Exponential...... 3 II-G Logarithm...... 3 References 8 II-H Power...... 4 II-I Pure Exponential Derivative...... 4 Appendix A: History 8 II-J Unit Logarithm Derivative...... 4 II-K Unit Angle...... 4 Appendix B: Derivation of Quaternion Multiplication 9 II-L Product Rule...... 4 B-A Derivation of Quaternion Basis Equalities9 B-B Derivation of Quaternion Multiplication9 III Representing Orientation 4 III-A Rotating a vector...... 5 III-B Chaining rotations...... 5 I.INTRODUCTION III-C Angular Derivatives...... 5 III-D Axis-Angle...... 5 Quaternions are a convenient representation for spatial mo- III-E Spherical Linear Interpolation.....5 tion that provides some computational advantages over other III-F Integration...... 5 methods. III-G Finite Difference...... 6 The straightforward definitions of many quaternion quan- tities, particularly exponentials, logarithms, and derivatives, IV Dual Quaternions and Euclidean Transforms 6 contain singularities where a denominator goes to zero. We can IV-A Dual ...... 6 avoid computational problems at these points by computing IV-B Representation...... 6 key factors near the singularity using a Taylor series, though IV-C Construction...... 6 this may require some careful rearrangement of terms to IV-D Multiplication...... 6 identify suitable factors and series. IV-E Matrix Form...... 6 A Taylor series evaluated near point a is: Quaternions

Associative p ⊗ (q ⊗ r) = (p ⊗ q) ⊗ r Distributive p ⊗ (q + r) = p ⊗ q + p ⊗ r ∞ (n) NOT Commutative p ⊗ q 6= q ⊗ p X f (a) ∗ ∗ ∗ f(x) = (x − a)n Conjugate Mul. (p ⊗ q) = q ⊗ p n! Conjugate Add. (p + q)∗ = q∗ + p∗ n=0 TABLE I f 0(a) f 00(a) ALGEBRAIC QUATERNION PROPERTIES = f(a) + (x − a) + (x − a)2 + 1! 2! f (3)(a) (x − a)3 + ... (1) 3! A. Representation To evaluate the infinite series to machine precision, we only We represent a quaternion as a 4-tuple of real numbers: need to compute up the term below floating point round-off. The resulting approximation is a polynomial which can q = w + xi + yj + zk be efficiently evaluated using Horner’s Rule, Algorithm1. = (x y z w) f(n)(a) The coefficients are the terms n! and the indeterminate = H(qv, w) (7) variable is x − a. Note than many Taylor series have zero coefficents for the odd or even terms. We can produce a more Historically, qv is called the vector part of the quaternion compact Horner polynomial by omitting the zero coefficients, and qw the scalar part. using (x − a)2 as the indeterminate variable, and perhaps It is convenient to define quaternion operations in terms of multiplying the whole result by (x − a). vector and matrix operations, so we also the whole quaternion as a column vector. This also provides an in-memory storage representation. Algorithm 1: Horner’s Rule T Input: b0, b1, . . . bn : Coefficients ~q = [x y z w] (8) Input: z : Indeterminate Variable T ~qv = [x y z] (9) Output: y : Result 1 y ← bn A alternate convention stores terms in wxyz order, so when 2 y ← bn−1 + zy using different software packages, it is sometimes necessary 3 y ← bn−2 + zy to convert between orderings. 4 ... 5 y ← b0 + zy B. Multiplication From the definition of the basis elements (2), we obtain a formula for quaternion multiplication. See section B for the detailed derivation. A. Notation 1) Cross and dot product definition: We define quaternion We adopt the following abbreviations to condense notation: multiplication in terms of cross products and dot products of its elements: • Quaternions are typeset as q. • Dual Quaternions are typeset as S.   ~qv × ~pv + qw~pv + pw~qv • Vectors are typeset as ~x. q ⊗ p = (10) qwpw − ~qv · ~pv • Matrices are typeset as A. • Time derivatives of variable x are given as x˙. 2) Matrix definition: Expanding the above terms, we can • Sines and cosines are abbreviated as s and c. express quaternion multiplication as matrix multiplication: q ⊗ p =   II.QUATERNIONS qw −qz qy qx q q −q q Quaternions are an extension of the complex numbers, using Q ~p =  z w x y  ~p = L −q q q q  basis elements i, j, and k defined as:  y x w z  −qx −qy −qz qw 2 2 2   i = j = k = ijk = −1 (2) pw pz −py px −pz pw px py  From (2), it follows: PR~q =   ~q =  py −px pw pz  −px −py −pz pw jk = −k j = i (3)   qxpw + qypz + qwpx − qzpy ki = −ik = j (4)  qzpx + qwpy + qypw − qxpz    (11) ij = −ji = k (5)  qwpz + qzpw + qxpy − qypx  −(qypy + qxpx + qzpz − qwpw) A quaternion, then, is: This matrix form is more suitable for efficient implementa- q = w + xi + yj + zk (6) tion computation using SIMD instructions.

2 Quaternions

3) Properties: Quaternion multiplication is associative and I distributive, but it is not commutative. 4) Pure Multiplication: When multiplying by a pure quater- nion, i.e., zero scalar part, we can simplify:

  qw −qz qy q q −q |q | ⊗ (v, 0) =  z w x v = v q −q q q   y x w  φ −qx −qy −qz  q v  q v   q v  R y z z y w x qw q v q v q v  z x  −  x z +  w y  (12)  q v  q v   q v   x y   y x  w z  Fig. 1. Imaginary Plane for Quaternions −qxvx qyvy −qzvz   qw qz −qy −qz qw qx  some useful trigonometric ratios for analyzing quaternion (v, 0) ⊗ q =   v =  qy −qx qw  functions: −qx −qy −qz       φ = atan2 (|qv| , qw) (19) vyqz vzqy vxqw |qv|  vzqx  vxqz  vyqw  sin (φ) = (20)   −   +   (13) |q|  vxqy  vyqx  vzqw  qw −vxqx vyqy −vzqz cos (φ) = (21)   |q| uyvz − uzvy    uzvx − uxvz  u × v The quaternion exponential is: (u, 0) ⊗ (v, 0) =   = (14)  uxvy − uyvx  −u · v  sin (|q |)  q qw v −uxvx − uyvy − uzvz e = e H qv , cos (|qv|) (22) |qv| Thus, the case of multiplying two pure quaternions simpli- fies to the commonly used cross (×) and dot (·) products. When |qv| approaches zero, we can use the Taylor series approximation: C. Norm sin (θ) θ2 θ4 θ6 = 1 − + − + ... (23) p θ 6 120 5040 |q| = ~q · ~q (15) For a pure quaternion, the exponential simplifies to: A unit quaternion has norm of one.   ( q sin(|qv |) e = H qv , cos (|qv|) |qv | D. Conjugate qw = 0 =⇒ (24) |eq | = 1 ∗ q = H(−qv, qw) (16) G. Logarithm E. Inverse To compute the logarithm, first consider the angle between the vector and scalar parts of the quaternion. q∗ q−1 = (17) ~q · ~q q  |q | φ = cos−1 w = sin−1 v = atan2 (|q | , q ) (25) Note that for unit quaternions, the inverse is equal to the |q| |q| v w conjugate. The atan2 form to compute φ is generally best for numerical F. Exponential stability. The exponential shows the relationship between quaternions   and complex numbers. Recall Euler’s formula for complex φ ln q = H qv, ln (|q|) (26) numbers: |qv|

φ iθ When |qv| approaches zero, we can compute as follows: e = cos (θ) + i sin (θ) (18) |qv | which relates the exponential function with angles in the φ φ φ φ complex plane. Similarly for quaternions, we can consider the = |q| = |q| = sin(φ) |q | (27) |qv| v sin (φ) |q| angle between the real and imaginary parts, Figure 1, yielding |q|

3 Representing Orientation

φ Representation Storage Then, sin(φ) can be approximated by Taylor series: Quaternion 4 Axis-Angle 4 θ θ2 7θ4 31θ6 Rotation Vector 3 = 1 + + + + ... (28) Euler Angles 3 sin (θ) 6 360 15120 Rotation Matrix 9 TABLE II For a unit quaternion, the logarithm simplifies to: STORAGE REQUIREMENTSFOR ORIENTATION REPRESENTATIONS   φ q = 1 =⇒ ln(q) = H qv, 0 (29) Representation Chain Rotate Point sin (φ) Quaternion 16 multiply, 12 add 15 multiply, 15 add Rotation Matrix 27 multiply, 18 add 9 multiply, 6 add TABLE III H. Power COMPUTATIONAL REQUIREMENTSFOR ORIENTATION REPRESENTATIONS

t t ln q φ q = e (30) d sin(φ) where we compute dt qv as follows: d cos−1 (w) w˙ I. Pure Exponential Derivative φ˙ = = dt sin (φ) Becase quaternion multiplication is not commutative, the φ d sin(φ) φ˙ φφ˙ cos (φ) chain rule does not apply to the quaternion exponential deriva- = − dt sin (φ) sin2 (φ) tive:  1 φ cos (φ) =w ˙ − + (39) d exp (f(q)) df(q) sin2 (φ) sin3 (φ) 6= ⊗ exp (f(q)) (31) dt dt Equations (38) and (39) have a singularity at φ = 0. We The derivative of the exponential for a pure quaternion is: can handle (38) with (28) and (39) with the following Taylor series: 1 φ cos (φ) 1 2 2 √ − + = − − φ2 − φ4 ... (40) φ = |qv| = qv · qv (32) sin2 (φ) sin3 (φ) 3 15 63 d |qv| qv · q˙v φ˙ = = (33) Alternatively, one could also use the Jacobian ∂ ln q = dt φ ∂q    2  q sin (φ) φ − φx − φxy − φxz − x e = H qv, cos (φ) (34) sin(φ) sin3(φ) sin3(φ) sin3(φ) sin2(φ)  2  φ  − φxy φ − φy − φyz − y   sin3(φ) sin(φ) sin3(φ) sin3(φ) sin2(φ)   q   2  de sin (φ) φxz φyz φ φz z ˙ − 3 − 3 − 3 − 2 = − sin (φ) φ = − (qv · q˙v) (35) sin (φ) sin (φ) sin(φ) sin (φ) sin (φ) (41) dt w φ ! deq  s φ˙c φ˙s = q˙v + − 2 qv = dt v φ φ φ K. Unit Quaternion Angle s  c s  q˙ + − (q · q˙ ) q = φ v φ2 φ3 v v v We can compute the angle between the vector forms of two  s  unit quaternions as follows: s c − φ q˙ + (q · q˙ ) q (36) φ v φ2 v v v −1 ∠(~q1, ~q2) = cos (~q1 · ~q2) = Then, we handle the singularity for φ = 0 using (23) and 2 atan2 (|q − q | , |q + q |) (42) the following: 1 2 1 2 The atan2 form is more accurate [1]. c s 1 φ2 φ4 φ6 2 − 3 = − + − + + ... (37) φ φ 3 30 840 45360 L. Product Rule Because quaternion multiplication is a linear operation (see J. Unit Logarithm Derivative section B), the product rule applies:

The derivative of the unit quaternion logarithm is: d  q1 ⊗ q2 = q˙1 ⊗ q2 + q1 ⊗ q˙2 (43) φ dt ln q = q sin (φ) v III.REPRESENTING ORIENTATION d φ d ln q sin(φ) φ = 1 = qv + q˙v (38) A unit quaternion ( q ) can represent an angular dt dt sin (φ) orientation.

4 Representing Orientation

A. Rotating a vector The rotation vector and quaternion derivatives are related as y = v y˙ = v˙ φ = |y| We can rotate point v by unit quaternion q by computing follows, substituting 2 , 2 , and : 0  ∗ v = rot q, v = q ⊗ v ⊗ q . Note that v is augmented with 0 in it’s w position to perform the quaternion multiplication op- y · y˙ φ˙ = (54) eration. Given this 0 value, the computation can be simplified φ to the following: sin (φ) q˙ = −φ˙ sin (φ) = (y · y˙) (55) w φ 0  v = rot q, v = sin (φ) φ˙ sin (φ) φ˙ cos (φ) ∗ q˙v = y˙ − 2 y + y = q ⊗ v ⊗ q = 2~qv × (~qv × v + qwv) + v (44) φ φ φ sin(φ) ! sin (φ) cos (φ) − which we can rewrite in a more SIMD-friendly form as: y˙ + φ (y ˙ · y) y (56) φ φ2

a = qv × v + qwv sin(φ) When φ goes to zero, we can approximate φ with the b = qv × a series in (23) and the other singular factor as: v0 = b + b + v (45) sin(φ) 2 4 6 cos (φ) − φ 1 φ φ φ 2 = − + − + + ... (57) B. Chaining rotations φ 3 30 840 45360

Rotations q1 and q2 are chained by multiplying the two E. Spherical Linear Interpolation quaternions: q1 ⊗ q2. Spherical Linear Interpolation, SLERP, interpolates between C. Angular Derivatives two quaternions. SLERP can be understood geometrically Rotational velocity ω is related to the quaternion derivative by considering a relative orientation in the axis-angle form. as follows: Consider the relative quaternion qr between two endpoints, q1 ⊗ qr = q2, given in axis angle form (ˆur, θr). To interpolate between q and q , we apply the q(τ) = q ⊗ q (τ), where q 1 1 2 1 s s q˙ = ω ⊗ q (46) is a rotation about uˆr with angle θs varying from 0 to θr as τ 2 varies from 0 to 1. We can compute the rotation vector form ω = 2q˙ ⊗ q∗ (47) of qs from that of qr as vs = τvr. Rotational acceleration ω˙ is related to the quaternion deriva- Composing definitions for quaternion and rotation vector tive as follows: conversion and quaternion exponents:

1  t ¨q = ω˙ ⊗ q + ω ⊗ q˙ (48) (τ) = ⊗ exp τ ln ∗ ⊗  = ⊗ ∗ ⊗  (58) 2 q q1 q1 q2 q1 q1 q2 1 ∗ ∗ π 3π = ω˙ = 2 ¨q ⊗ q + q˙ ⊗ q˙ (49) To interpolate in the shorter direction, e.g., − 2 vs. + 2 , 2 ∗ scale q1 ⊗ q2 so it has a positive scalar element. A more efficient computation for SLERP [2] is: D. Axis-Angle The axis-angle form, a = (ˆu, θ) represents rotation by angle θ around unit axis uˆ. We can also normalize the representation φ = |∠(~q1, ~q2)| (59) ( by scaling the axis by the angle v = θuˆ, which is sometimes φ > π π − φ called the rotation vector form. θ = 2 (60) φ ≤ π φ Rotation vectors are related to unit quaternions through the 2 ( π sin(θ−τθ) sin(τθ) exponential and logarithm. φ > q1 − q2 q(τ) = 2 sin(θ) sin(θ) (61) φ ≤ π sin(θ−τθ) q + sin(τθ) q      2 sin(θ) 1 sin(θ) 2 θ θ θ uˆ q = H uˆ sin , cos = e 2 = 2 2      F. Integration v |v| |v| v H sin , cos = e 2 (50) |v| 2 2 Euler or Runge-Kutta integration of quaternion derivatives would not preserve the unit constraint, introducing error. We can instead integrate a constant rotational velocity with: −1 −1 θ = 2 cos (qw) = 2 tan (|qv| , qw) = 2 |ln q| (51) (θ 6= 0 qv sin θ ln q ω∆t uˆ = ( 2 ) = (52) q1 = exp ⊗ q0 (62) θ = 0 0 |ln q| 2 ∗ v = 2 ln q (53) = exp ∆tq˙ ⊗ q0 ⊗ q0 (63)

5 Dual Quaternions and Euclidean Transforms

G. Finite Difference C. Construction Based on (62), we can compute a finite difference velocity We can produce a dual quaternion for some transformation represented by the rotational quaternion q, and the translation ω∆ between two orientations: vector v as follows:

∗ r = q (76) ω∆ = 2 ln q1 ⊗ q0 (64) 1 ∗ d = v ⊗ r (77) q˙∆ = ln q1 ⊗ q0 ⊗ q0 (65) 2 Translation v is augmented with 0 as the scalar element for r IV. DUAL QUATERNIONS AND EUCLIDEAN TRANSFORMS the quaternion multiply. The real part represents orientation, and the dual part d represents translation. Note that the real Dual quaternions are convenient for representing Euclidean part r will be a unit quaternion while the dual part d has no transformations. Formally, dual quaternions are the general- such restriction. ization of quaternions to dual numbers. To extract the translation, we do:

v = 2 ⊗ ∗ (78) A. Dual Numbers d r

Dual numbers are similar to complex numbers, but the D. Multiplication square of the dual element ε is zero: Multiplication is defined in terms of the standard quaternion z˜ = a + bε (66) multiply, performed over both real and dual parts: ε 6= 0 (67)   A ⊗ B = Sar ⊗ br , ar ⊗ bd + ad ⊗ br  (79) ε2 = 0 (68) E. Matrix Form If we consider the Taylor series of f(a + bε) at point a, we obtain the following property: We can also represent the dual quaternion multiplication as a matrix multiply. Based on (11): f(a + bε) = f(a) + bf 0(a)ε (69)   ar ⊗ br This lets us define a few functions for dual numbers: A ⊗ B = = ar ⊗ bd + ad ⊗ br   Ar,L 0 cos (a + bε) = cos (a) − sin (a) bε (70) ALB~ = B~ = Ad,L Ar,L sin (a + bε) = sin (a) + cos (a) bε (71)   a a ~ Br,R 0 ~ exp (a + bε) = e + e bε (72) BRA = A (80) Bd,R Br,R √ √ b a + bε = a + √ ε (73) 2 a F. Conjugate

B. Representation ∗  ∗ ∗ S = Ssr , sd  (81) Dual quaternions are quaternions with dual numbers for elements. G. Exponential S = We derive the dual quaternion exponential by expanding x˜ +y ˜ +z ˜ +w ˜ = i j k (22) using dual arithmetic: (rx + dxε)i + (ry + dyε)j + (rz + dzε)k + (rw + dwε) = (rxi + ryj + rzk + rw) + (dxi + dyj + dzk + dw)ε = r + d ε (74) φ = |rv| (82)

k = rv · dv (83)     c − s  S w˜ s s φ s e = e SH rv, c , H dv + krv, − k  (84) For computation, it is convenient to represent dual quater-  φ φ φ2 φ  nion S factored into the separate real and dual parts r and d : where w˜ = rw + dwε. Then, to handle the singularity at φ = 0, we use (23) and: S = r + d ε sin(φ) 2 4 6   cos (φ) − φ 1 φ φ φ = − + − + + ... (85) = Sr, d  (75) φ2 3 30 840 45360

6 Implicit Dual Quaternions

Representation Storage H. Logarithm Dual Quaternion 8 We derive the dual quaternion logarithm by expanding (26) Implicit Dual Quaternion 7 Transformation Matrix 12 using dual arithmetic: TABLE IV STORAGE REQUIREMENTSFOR TRANSFORMATION REPRESENTATIONS

φ = atan2 (|rv| , rw) (86) Representation Chain Transform k = rv · dv (87) Dual Quaternion 48 multiply, 40 add 28 multiply 28 add φ 2 Implicit Dual Quaternion 31 multiply, 30 15 multiply, 18 add rw − |r| α = |rv | (88) Transformation Matrix 36 multiply, 27 add 9 multiply, 9 add 2 TABLE V |rv| COMPUTATIONAL REQUIREMENTSFOR ORIENTATION REPRESENTATIONS  φ  (ln S)r = H rv, ln |r| (89) |rv| ! kα − dw φ k + rwdw 2) Angular Velocity: Angular velocity computation is iden- (ln S)d = H 2 rv + dv, 2 (90) |r| |rv| |r| tical to the single unit quaternion case: 1 To handle the singularity at |rv| = 0, we apply (27) and r˙ = ω ⊗ r (97) (28) to handle φ . Then, we rewrite α as: 2 |rv | ω = 2˙r ⊗ r ∗ (98)

φ 2 3) Translational Velocity: We find the equation for the rw − |r| |rv | = derivative of the dual part by differentiating (77), |r |2 v 1 2 d˙ = (v˙ ⊗ r + v ⊗ r˙) (99) rw φ |r| 2 2 − 3 = |rv| |rv| Translational velocity comes from differentiating (78): 2 3 r |r| φ |r| ∗ ∗ w v˙ = 2(d˙ ⊗ r + d ⊗ (˙r) ) (100) 2 2 − 3 = |rv| |r| |rv| |r| 2 3 ! 1 rw |r| |r| L. Integration 2 − φ 3 = |r| |r| |rv| |rv| To integrate dual quaternions, we first introduce the twist, 1  cos (φ) φ  Ω:   − (91) Ω = SH(ω, 0) , H(v ˙ + v × ω, 0) (101) |r| sin2 (φ) sin3 (φ) This gives the Taylor series: where ω is angular velocity, v is translation, and v˙ is transla- tional velocity. c φ 2 1 17 29 − = − − φ2 − φ4 − φ6 + ... (92) Then, integration of a constant velocity is given by: 2 3 3 5 420 4200 s s Ω∆t S = exp ⊗ S (102) 1 2 0 I. Chaining Transforms Transforms are chained by multiplying the dual quaternions. V. IMPLICIT DUAL QUATERNIONS We can implicitly represent the dual quaternion for a J. Transforming a point Euclidean transform by storing orientation quaternion r and We can transform a point v by constructing a dual quater- translation vector v: nion for translation v and identity rotation, and chaining it   E = Sir, v (103) onto the transform, then extracting the resulting translation:  1  This form allows more efficient computation for some S 0 = S ⊗ SH(0, 1) , v (93)  2  operations. v0 = 2s0 ⊗ s0∗ (94) d r A. Chaining transforms This reduces to: From dual quaternion multiplication (79), we derive the 0 ∗ multiplication formula for the implicit form: v = (2sd + sr ⊗ v) ⊗ sr (95) ∗ Cv = 2Cd ⊗ Cr = ∗ K. Derivatives 2 (Ar ⊗ Bd + Ad ⊗ Br) ⊗ (Ar ⊗ Br) =   1) Product Rule: Because dual quaternion multiplication is Bv ⊗ Br Av ⊗ Ar ∗ ∗ 2 Ar ⊗ + ⊗ Br ⊗ B ⊗ A = a linear operation (see section B), the product rule applies: 2 2 r r ∗ (Ar ⊗ Bv + Av ⊗ Ar) ⊗ Ar = d ∗ (S1 ⊗ S2) = S˙1 ⊗ S2 + S1 ⊗ S˙2 (96) A ⊗ B ⊗ A + A dt r v r v

7 Derivation of Quaternion Multiplication

This is equivalent to rotating Bv by Ar, then adding Av. D. Chaining Transforms Thus, we chain transforms with:

Cr = Ar ⊗ Br (104) R R (R v + v ) C = AB = A B A B A (111) Cv = rot (Ar,Bv) + Av (105) 0 1

B. Transforming points REFERENCES To transform point p, we first rotate it by the given orien- [1]K AHAN, W. How futile are mindless assessments of roundoff in floating- tation r, then add the translation v point computation. Tech. rep., U.C. Berkeley, 2006. http://www.cs. ∼ p0 = rot (r, p) + v berkeley.edu/ wkahan/Mindless.pdf. (106) [2]S HOEMAKE, K. Animating rotation with quaternion curves. ACM SIGGRAPH computer graphics 19, 3 (1985), 245–254. C. Conjugate

From the dual quaternion conjugate (81) for S = (r, d): GLOSSARY ∗ ∗ ∗ ∗ (S )v = 2(S )d ⊗ ((S )r) = axis-angle 2d∗ ⊗ (r∗)∗ = Rotation representation (ˆu, θ), where uˆ is a unit 1 vector representing an axis of rotation and θ is an 2( v ⊗ r)∗ ⊗ r = 2 angle to rotate about uˆ.5 (v ⊗ r)∗ ⊗ r = dual Number with dual element ε, where ε2 = 0.6 r∗ ⊗ v∗ ⊗ r = ∗ pure quaternion − rot (r , v) A quaternion with zero scalar part.3,4 Thus, to find the conjugate translation, we rotate v by r∗ rotation vector and negate. Scaled form of the axis-angle representation, v = θuˆ. 5 D. Derivatives scalar The real part of the quaternion, i.e., the w element. The transform chaining in (105) is not linear, so we cannot 2,3 apply the product rule. Instead, we directly differentiate (105): SIMD Single Instruction Multiple Data. Type of CPU in-      d r1 r2 structions which perform multiple computations with Si  ⊗ Si  = dt v1 v2 a single instruction, such as element-wise addition or   r˙1 ⊗ r2 + r1 ⊗ r˙2 multiplication of several values.2,5 Si ∗ ∗ ∗(107) v˙1 +q ˙1 ⊗ v2 ⊗ q1 + q1 ⊗ v˙2 ⊗ q1 + q1 ⊗ v2 ⊗ q˙1  unit quaternion A quaternion with norm of one.3,4 VI.MATRICES AND EUCLIDEAN TRANSFORMS vector A. Rotation Matrix The imaginary part of the quaternion, i.e., the x, y, Using the matrix expansions of quaternion multipication, we and z elements.2,3 can rewrite the quaternion rotation operator as a single matrix multiply: ∗ ∗ ∗ q ⊗ v ⊗ q = QL~v ⊗ q = (Q )RQL~v = R~v = APPENDIX A  2 2 2 2  −qz − qy + qx + qw 2qxqy − 2qz qw 2qxqz + 2qy qw HISTORY 2 2 2 2  2qz qw + 2qxqy −qz + qy − qx + qw 2qy qz − 2qxqw  v (108) 2 2 2 2 2qxqz − 2qy qw 2qy qz + 2qxqw qz − qy − qx + qw Quaternions were invented in the mid-nineteenth century by , who spent the rest of his life The matrix R has geometric significance as well. The ith exploring their properties. They quickly found use among column of a R is the ith axis of the child frame in the parent physicists; Maxwell’s equations were originally formulated frames coordinates. using quaternions. Around the turn of the twentieth century, Josiah Gibbs B. Transformation Matrix published his Vector Analysis, presented as a simplification over quaternions. The chief distinction was the invention of R v T = (109) the dot and cross product operators, splitting quaternion mul- 0 1 tiplication into two separate operations. Eventually, Gibbs’s notation overtook quaternions as the representation of choice C. Transforming Points among physicists and engineers. Though quaternions may have lost the overall popularity p0 T ~p + T  contest to Gibbs’s vector analysis, their useful numerical = T~p = R v (110) 1 1 properties mean quaternions still have some role to play.

8 Derivation of Quaternion Multiplication

APPENDIX B 4) Simplify basis elements again: DERIVATION OF QUATERNION MULTIPLICATION =⇒ pwqw + pwqxi + pwqyj + pwqzk + First, the basis elements axiom: pxqwi − pxqx + pxqyk − pxqzj+ 2 2 2 i = j = k = ijk = −1 pyqwj − pyqxk − pyqy + pyqzi+

pzqwk + pzqxj − pzqyi − pzqz A. Derivation of Quaternion Basis Equalities 5) Combine terms by basis element:

=⇒ (pwqx + pxqw + pyqz − pzqy)i+

ijk = −1 (pwqy − pxqz + pyqw + pzqx)j+

ijkk = −k (pwqz + pxqy − pyqx + pzqw)k +

−ij = −k (pwqw − pxqx − pyqy − pzqz) = ij k 6) Reorder the terms: iij = ik =⇒ (pyqz − pzqy + pwqx + qwpx)i+ −j = ik (pzqx − pxqz + pwqy + qwpy)j+ −jj = jik (pxqy − pyqx + pwqz + qwpz)k + 1 = jik (p q − p q − p q − p q ) k = jikk w w x x y y z z p × q + p q + q p  k = −ji = v v w v v v pwqw − pv · qv ki = −jii ki = j jki = jj jki = −1 jkii = −i jk = i jkk = ik −j = ik −jj = ikj 1 = ikj i = iikj i = −kj

B. Derivation of Quaternion Multiplication 1) Multiply the two quaternions:

p ⊗ q = (pw + pxi + pyj + pzk )(qw + qxi + qyj + qzk )

2) Distribute terms of q1 over terms of q2:

=⇒ pw(qw + qxi + qyj + qzk )+

pxi(qw + qxi + qyj + qzk )+

pyj(qw + qxi + qyj + qzk )+

pzk (qw + qxi + qyj + qzk ) 3) Distribute again:

=⇒ pwqw + pwqxi + pwqyj + pwqzk + 2 pxqwi + pxqxi + pxqyij + pxqzik + 2 pyqwj + pyqxji + pyqyj + pyqzjk + 2 pzqwk + pzqxki + pzqykj + pzqzk

9