. Introduction Introduction to uaternions Invented and developed by William Hamilton in 843, uaternions are essentially a generalization of complex numbers to four dimensions (one real dimension, three imaginary). Quaternions have important, desirable properties when used to represent rotations, and, as such, are worthy of study in this course, where rotations between coordinate frames will occupy much of our attention, especially early on. This document gives a brief introduction on uaternions and follows closely the notation in [, which offers a much more exhaustive treatment. 2. Basic definition A uaternion consists of a scalar part s, s R, and a vector part v ( xyz,, ), v R 3. We will use several different forms to denote uaternions. These are given in euations () through (3) below: [ s, v [ s, ( xyz,, ) s+ ix + jy + kz In definition (3) above, the imaginary number i, j and k have the following properties: i 2 j 2 k 2 () (2) (3) (4) ij k (5) ji k From (4) through (6) the following additional properties can be derived: ijk (6) (7) jk i (8) kj ik i j (9) (0) ki j 3. Basic properties () A. Addition Let, and, ' Then, [ s, v [ s, ( x, yz, ), (2) [ s', v' [ s',( x', y', z' ). (3) + ' [ s + s', v+ v' ( s + s' ) + i( x+ x' ) + j( y+ y' ) + k( z + z' ) Clearly, uaternion addition is associative and commutative. (4) B. Multiplication With definitions (2) and (3), the product of two uaternions and ' is given by, - -
' [ ss' v v', v v' + sv' + s'v Euation (5) can be verified by writing, (5) ' [ s, v [ s', v' ( s + ix + jy + kz) ( s' + ix' + jy' + kz' ) expanding the product in euation (6), applying properties (4) through (), and grouping terms accordingly. As a reminder, note that for two vectors a ( a x, a y, a z ) and b ( b x, b y, b z ), the dot and cross products are defined as, (6) a b a x b x + a y b y + a z b z b a (7) a b ( a y b z a z b y, a z b x a x b z, a x b y a y b x ) b a (8) respectively. Note that two purely scalar uaternions, [ s, 0 and [ s', 0, result in a scalar product, while two purely vector uaternions, [ 0, v and [ 0, v', yield both the dot product (albeit negative), and the cross product, [ 0, v [ 0, v' [ v v', v v'. (9) It can be easily verified that multiplication is associative, but not commutative; that is, in general, the order of multiplication does matter. One case of multiplication that is commutative is multiplication of a general uaternion by a scalar uaternion: C. Conjugate [ r, 0 [ s, v [ s, v [ r, 0 [ rs, rv. (20) The conjugate of a uaternion [ s, v is denoted as and is defined as, D. Norm [ s, v. (2) The norm (or length) of a uaternion [as defined in euation (2) is given by, (22) Since, [ s 2 ( v ( ), v ( + sv + s( [ s 2 + v v, 0 euation (22) can be expanded to, (23) Note the similarity of euation (24) to the computation of the length of a vector. A unit uaternion is any uaternion of unit length such that. E. Inversion s 2 + x 2 + y 2 + z 2 The inverse of a uaternion [as defined in euation (2) is given by, 2. (25) This can be easily verified by computing : 2 2 2 [, 0. (26) (24) - 2 -
4. Rotations through uaternions A. Basics Below we will show that every unit uaternion represents a uniue rotation in space. It is easy to show that any unit uaternion can be expressed as, where kˆ ( k x, k y, k z ) denotes an arbitrary unit vector. Such a unit uaternion represents a rotation of θ about the vector kˆ. Now, let p ( p x, p y, p z ) denote the Cartesian coordinates of a point in space. Let us assume that we wish to rotate p by θ about the vector kˆ to. Let, Then, [ cos( θ 2), sin( θ 2) kˆ p [ 0, p, and, (28) [ 0,. (29) p In words, rotation by an angle θ about a unit vector kˆ can be achieved by pre- and post-multiplying the uaternion representation p of the vector p by the uaternion [as given by (27) and its conjugate, respectively. Let us show that euation (30) results in the same rotation matrix R ( θ) as previously derived in class kˆ through an argument of composite rotations (as demonstrated in Mathematica). p (27) (30) (3) [ s, v [ 0, p [ s, v (32) [ v p, v p+ sp [ s, v (33) Now, expression (34) can be significantly simplified. Note that the scalar part of (34) reduces to zero, since the dot products s( v and s( p cancel each other, and, which can be verified by inserting definitions (7) and (8) for the dot and cross products, respectively, into (35). For the vector part, and, so that, [ s( v + ( v v + s( p, ( v v s( p + s( v + s 2 p + v( v ( v v 0 s( p + s( v 2s( v ( v v ( v p ( v v [easily verified through (7) and (8) (37) (34) (35) (36) [ 0, ( s 2 v p + 2s( v + 2( v v or, euivalently, (38) ( s 2 v p + 2s( v + 2( v v. (39) We are now ready to substitute (27) into (39): [ cos 2 ( θ 2) sin 2 ( θ 2) p + 2cos( θ 2) sin( θ 2) kˆ p + 2sin 2 ( θ 2) ( kˆ kˆ (40) - 3 -
Applying the following trigonometric half-angle identities, cosθ cos 2 ( θ 2) sin 2 ( θ 2) sinθ 2cos( θ 2) sin( θ 2) ( cosθ) ( cos 2 ( θ 2) + sin 2 ( θ 2) ) 2sin 2 ( θ 2) (4) (42) [from (4) and (42) (43) euation (40) simplifies even further to: ( cosθ)p + ( sinθ)kˆ p + ( cosθ) ( kˆ kˆ (44) ( cθ)p + ( sθ)kˆ p + ( vθ) ( kˆ kˆ, (45) where cθ cosθ, sθ sinθ and vθ cosθ. Euation (44) is an important result known as Rodrigues formula. When we expand euation (45) by component terms, we get (after a lot of math best left to Mathematica), R ( θ)p kˆ (46) R ( θ) kˆ ( k 2 x vθ + cθ) ( k x k y vθ k z sθ) ( k x k z vθ + k y sθ) ( k x k y vθ + k z sθ) ( k 2 y vθ + cθ) ( k y k z vθ k x sθ) ( k x k z vθ k y sθ) ( k y k z vθ + k x sθ) ( k 2 y vθ + cθ) (47) which is exactly the same result as obtained in class through an argument of composite rotations. The two most important euations in this section are (3) and (45), which are reprinted below to emphasize their importance: p [rotation through uaternions (48) ( cθ)p + ( sθ)kˆ p + ( vθ) ( kˆ kˆ [Rodrigues formula (49) B. Composite uaternion rotations Assume two rotations: o followed by. The result of the first rotation is given by, 0 p 0 (50) while the result ' after both rotations is given by, ' (5) ' ( 0 p 0 ) (52) ' ( 0 )p ( 0 ) ' ( 0 )p ( 0 ) (53) (54) Note that from (53) to (54) we used the following fact: 0 ( 0 ) (55) for unit uaternions, which can be readily shown through the definition of uaternion multiplication. Euation (55) is important in that it shows that composite rotations can be computed through simple unit uaternion multiplication. - 4 -
C. Quaternion to axis-angle representation For any uaternion, [ s, v (56) we can readily compute the euivalent axis-angle representation. From (27), [ cos( θ 2), sin( θ 2) kˆ we can compute θ and kˆ as: θ 2atan( v, s) kˆ v v (57) (58) (59) Note that when rotation. θ 0 D. Quaternion to rotation matrix Suppose we have a uaternion,, the axis of rotation becomes ill-conditioned, since any axis is euivalent for a null [ s, ( xyz,, ). (60) and would like to identify the corresponding 3 3 rotation matrix R. We start by expanding euation (39) into the components of v ( xyz,, ): ( s 2 v p + 2s( v + 2( v v (6) ( s 2 x 2 y 2 z 2 ) 00 00 00 0 z y + 2s z 0 x + 2 y x 0 x 2 xy xz xy y 2 yz p xz yz z 2 (62) 2( y 2 + z 2 ) 2( xy sz) 2( xz + sy) 2( xy + sz) 2( x 2 + z 2 ) 2( yz sx) 2( xz sy) 2( yz + sx) 2( x 2 + y 2 ) p (63) Note that in (62), we used the following matrix representation of the cross product: ( v 0 z y z 0 x y x 0 p (64) which is easily verified by doing a component-by-component comparison of both sides of euation (64). Thus, R is given by, R 2( y 2 + z 2 ) 2( xy sz) 2( xz + sy) 2( xy + sz) 2( x 2 + z 2 ) 2( yz sx) 2( xz sy) 2( yz + sx) 2( x 2 + y 2 ) (65) E. Rotation matrix to uaternion Suppose we have a rotation matrix R, - 5 -
r r 2 r 3 R r 2 r 22 r 23 (66) r 3 r 32 r 33 such that, Rp, (67) and would like to identify the corresponding uaternion, [ s, ( xyz,, ). (68) From the result of the previous section in (65), we can write down the following 0 convenient euations relating r ij to [ s, ( x, yz, ): s 2 -- ( + r 4 + r 22 + r 33 ) x 2 -- ( + r 4 r 22 r 33 ) y 2 -- ( r 4 + r 22 r 33 ) z 2 -- ( r 4 r 22 + r 33 ) (69) (70) (7) (72) and, sx 4 32 r 23 ) (73) sy 4 3 r 3 ) (74) sz 4 2 r 2 ) (75) xy 4 2 + r 2 ) (76) xz 4 3 + r 3 ) (77) yz 4 23 + r 32 ) (78) Now, to solve for the parameters [ s, ( x, yz, ) robustly, use the first four euations [(69) through (72), to solve for the largest valued parameter in { s 2, x 2, y 2, z 2 }. Then, solve for the remaining three parameters using three of the six remaining euations [(73) through (78). 5. Rotation trajectories through uaternions A. Linear interpolation (Ler Suppose you wish to generate a trajectory of orientations between two rotations represented by unit uaternions 0 and respectively. One method of achieving this is called Linear Interpolation (Ler, which is given by, - 6 -
where, Lerp( 0,, h) f ( 0,, h) -------------------------------, h [ 0,, (79) f ( 0,, h) f ( 0,, h) 0 ( h) + h. (80) Note that the normalization in euation (79) is reuired since f ( 0,, h) is not guaranteed to be a unit vector. It is easy to verify that, Lerp( 0,, 0) 0, and, (8) Lerp( 0,, ). (82) See [ for much more detail. B. Spherical linear interpolation (Sler One of the main objections to the Lerp trajectory is that the resulting trajectory is not constant velocity. Another method, called Spherical Linear Interpolation (Sler, achieves the shortest possible interpolation path between 0 and (or 0 and, whichever is shorter) along the four-dimensional unit sphere at constant velocity. The Slerp interpolation is given by, Slerp( 0,, h) ( 0 ) h 0, h [ 0,, (83) or euivalently as, Slerp( 0,, h) ( 0 ) h 0, h [ 0,. (84) Note that as was the case for Lerp, Slerp( 0,, 0) ( 0 ) 0 0 0 0, and, (85) Slerp( 0,, ) ( 0 ) 0 0 0. (86) The main difference between the Lerp and the Slerp interpolation is that the Lerp interpolation cuts through the unit uaternion sphere (before being projected back onto it through normalization), while the Slerp interpolation moves at constant velocity on the surface on the unit uaternion sphere. (see Figure 6.4 on page 42 in [). In order to compute (83) [or (84) for uaternion of the form, where kˆ is a unit vector, we define, h ( 0, ), we need a little more uaternion math. First, given a unit log( ) [ 0, Ωkˆ. (88) Second, for a uaternion of the form, we define, [ cosω, sinωkˆ [ 0, Ωkˆ exp( ) [ cosω, sinωkˆ. (90) Now, we define, (87) (89) h exp[ h log( ) (9) - 7 -
These definitions have some familiar (with respect to scalars) properties, such as: log( [ 0, ) [ 00,, (92), (93) A word of caution, though; not all properties scale from scalars to uaternions; for example, for uaternions p,. Now, we are ready to give a formula for computing the Slerp interpolation. Let, so that, 0 [ s 0, v 0, and, (96) [ s, v. (97) 0 [ s s 0 + ( v v 0 ), v v 0 + s 0 v s v 0. (98) If we let, a b a+ b ab ( a ) b. (94) log( p) log( + log( ) (95) 0 [ cosω, sinωkˆ [as in assumption (87), (99) then, cosω 0 s s 0 + ( v v 0 ) (00) Ω acos( 0 ), and, (0) k v 0 v + s 0 v s v 0, and, (02) kˆ k/ k 0 k 0 k 0 (03) Finally [from definition (9), ( 0 ) exp[ h log( 0 ) ( 0 ) exp( [ 0, hωkˆ ) (04) (05) ( 0 ) h [ cos( hω), sin( hω) kˆ. (06) Euation (06), together with (00) through (03), allows computation of Slerp( 0,, h) ( 0 ) h 0, h [ 0,. From (06), note that ( 0 ) 0 [, 0 and ( 0 ) 0. For much greater detail, see [. 6. Conclusions Unit uaternions represent rotations. They have several advantages over three-angle representations (both fixed axis and Euler angles) and rotation matrices:. Unit uaternions do not suffer from singularities, as three-angle conventions do. 2. Unit uaternions represent the most compact way of representing rotations without redundancy or singularity (unlike rotation matrices themselves). One can visualize unit uaternions populating the surface of a sphere in four-dimensional Euclidean space, where each uaternion and its antipode represent a uniue rotation in three dimensions. - 8 -
References 3. The unit uaternion representation allows us to define and compute a distance metric between two rotations. This is not, in general possible or easy with three-angle conventions or rotation matrices. 4. In finite-precision computations, ensuring proper rotations through freuent re-normalization is easy for unit uaternions, but significantly trickier for rotation matrices. 5. For simulation purposes, it is easy to generate a uniformly random distribution of rotations in uaternion space. 6. Unit uaternions allow for the computation of shortest-path, smooth, continuous-velocity trajectories between two rotations (represented as unit uaternions). Three-angle conventions make this very difficult, if not impossible. [ E. B. Dam, M. Koch and M. Lillholm, Quaternions, Interpolation and Animation, DIKU-TR-98/5, Technical Report, Department of Computer Science, University of Copenhagen, 998 (http://www.diku.dk/ research/published/98-5.ps.gz). - 9 -