Quaternions Basilio Bona DAUIN Politecnico di Torino Semester 1, 2016-2017 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 1 / 40
Introduction Complex numbers with unit norm can be used as rotation operators in the 2D plane. Quaternions were discovered in 1843 by Sir William Hamilton, who was trying to find new hyper-complex numbers as rotation operators in 3D space. Figure: Sir William Rowland Hamilton (1805-1865) and the plaque on Broom Bridge, where he discovered the quaternions. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 2 / 40
Definitions The generic quaternion will be indicated as q. Quaternions are elements of a 4D linear space H(R), defined on the real numbers field F = R, with base {1 i j k}. i, j and k are hypercomplex numbers that satisfy the following anticommutative multiplication rules: i 2 = j 2 = k 2 = ijk = 1 ij = ji = k jk = kj = i ki = ik = j Notice the similarity of quaternions i, j and k with the basis vectors i, j and k B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 3 / 40
Definitions A quaternion q H is defined as a linear combination expressed in the base {1 i j k}: q = q 0 1 + q 1 i + q 2 j + q 3 k where the coefficients {q i } 3 i=0 are real. Another way to represent a quaternion is to define it as a quadruple of reals, (q 0,q 1,q 2,q 3 ) q = (q 0,q 1,q 2,q 3 ) in analogy with complex numbers c = a + jb, where c is represented by a couple of reals, c = (a,b), B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 4 / 40
Definitions Quaternions are also defined as hypercomplex numbers, i.e., those complex numbers having complex coefficients: where c 1 = q 0 + kq 3 e c 2 = q 2 + kq 1. q = c 1 + jc 2, Therefore, considering multiplication rules, it results: q = c 1 + jc 2 = q 0 + kq 3 + jq 2 + jkq 1 = q 0 1 + q 1 i + q 2 j + q 3 k B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 5 / 40
Definitions In analogy with complex numbers that are the sum of a real part and an imaginary part, quaternions are the sum of a real part and a vectorial part. The real part q r is defined as q r = q 0, and the vectorial part q v is defined as q v = q 1 i + q 2 j + q 3 k. We write q = (q r, q v ) or q = q r + q v ; note that the vectorial part is not transposed since the conventional definition for the vectorial part of a quaternion assumes a row representation. Using the convention that defines vectors as column vectors, we can write q = (q r, q T v ). B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 6 / 40
Definitions Quaternions are mathematical objects that include real numbers r = (r, 0, 0, 0), r R complex numbers a + ib = (a, b, 0, 0), a,b R real vectors in R 3 (with some caution, since not all vectorial parts represents vectors) v = (0, v 1, v 2, v 3 ), v i R. In this last case, elements { i j k } are to be understood as unit vectors { i j k } forming an orthonormal base in a cartesian right-handed reference frame. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 7 / 40
Definitions Multiplication rules between elements i, j, k have the same properties of the cross product between unit vectors i,j,k: ij = k i j = k ji = k j i = k etc. In the following we will use all the possible alternative notations to indicate quaternions q = q 0 1 + q 1 i + q 2 j + q 3 k = (q r,q v ) = q r + q v = (q 0,q 1,q 2,q 3 ) i.e., a) a hypercomplex number; b) the sum of a real part and a vectorial part; c) a quadruple of reals. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 8 / 40
Definitions Another way to write a quaternion is using 2 2 complex matrices q = q 0 1 + q 1 i + q 2 j + q 3 k where 1 = [ ] [ ] 1 0 i 0 ; i = ; j = 0 1 0 i [ ] 0 1 ; k = 1 0 [ ] 0 i ; i 0 and i 2 = 1. Hence every matrix is of the form [ ] c d d c ; These matrices are called Cayley matrices [see slide on Rotations - Pauli spin matrices]. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 9 / 40
Quaternions algebra Given a quaternion q = q 0 1 + q 1 i + q 2 j + q 3 k = q r + q v = (q 0,q 1,q 2,q 3 ), the following properties hold: null or zero 0 quaternion 0 = 01 + 0i + 0j + 0k = (0,0) = 0 + 0 = (0,0,0,0) conjugate quaternion q, having the same real part and the opposite vectorial part: q = q 0 (q 1 i + q 2 j + q 3 k) = (q r, q v ) = q r q v = (q 0, q 1, q 2, q 3 ) Conjugate quaternion satisfies (q ) = q B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 10 / 40
Quaternions algebra non-negative function, called quaternion norm q, defined as q 2 = qq = q q = 3 l=0 q 2 l = q 2 0 + q T v q v A quaternion with unit norm q = 1 is called unit quaternion. Quaternion q and its conjugate q have the same norm The quaternion q = q q v = 01 + q 1 i + q 2 j + q 3 k = (0,q v ) = 0 + q v = (0,q 1,q 2,q 3 ), that has a zero real part is called pure quaternion or vector. The conjugate of a pure quaternion q v is the opposite of the original pure quaternion q v = q v B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 11 / 40
Quaternions algebra Given two quaternions h = h 0 1 + h 1 i + h 2 j + h 3 k = (h r,h v ) = h r + h v = (h 0,h 1,h 2,h 3 ) and g = g 0 1 + g 1 i + g 2 j + g 3 k = (g r,g v ) = g r + g v = (g 0,g 1,g 2,g 3 ) the following operations are defined B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 12 / 40
Sum Sum or addition h + g h + g = (h 0 + g 0 )1 + (h 1 + g 1 )i + (h 2 + g 2 )j + (h 3 + g 3 )k = ((h r + g r ), (h v + g v )) = (h r + g r ) + (h v + g v ) = (h 0 + g 0,h 1 + g 1,h 2 + g 2,h 3 + g 3 ) B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 13 / 40
Difference Difference or subtraction h g = (h 0 g 0 )1 + (h 1 g 1 )i + (h 2 g 2 )j + (h 3 g 3 )k = ((h r g r ), (h v g v )) = (h r g r ) + (h v g v ) = (h 0 g 0,h 1 g 1,h 2 g 2,h 3 g 3 ) B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 14 / 40
Product Product hg = (h 0 g 0 h 1 g 1 h 2 g 2 h 3 g 3 )1 + (h 1 g 0 + h 0 g 1 h 3 g 2 + h 2 g 3 )i + (h 2 g 0 + h 3 g 1 + h 0 g 2 h 1 g 3 )j + (h 3 g 0 h 2 g 1 + h 1 g 2 + h 0 g 3 )k = (h r g r h v g v, h r g v + g r h v + h v g v ) where h v g v is the scalar product h v g v = h vi g vi = h T v g v = g T v h v i defined in R n, and h v g v is the cross product (defined only in R 3 ) h v g v = h 2g 3 h 3 g 2 h 3 g 1 h 1 g 3 = S(h v )g v h 1 g 2 h 2 g 1 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 15 / 40
Product The quaternion product is anti-commutative, since, being it follows that g v h v = h v g v gh = (h r g r h v g v, h r g v + g r h v h v g v ) hg Notice that the real part remains the same, while the vectorial part changes. Product commutes only if h v g v = 0, i.e., when the vectorial parts are parallel. The conjugate of a quaternion product satisfies this relation (gh) = h g The product norm satisfies this relation gh = hg = g h = h g B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 16 / 40
Product properties The quaternion product has the following properties associative multiplication by the unit scalar (gh)p = g(hp) 1q = q1 = (1,0)(q r,q v ) = (1q r,1q v ) = (q r,q v ) multiplication by the real λ bilinearity, with real λ 1,λ 2 λq = (λ,0)(q r,q v ) = (λq r,λq v ) g(λ 1 h 1 + λ 2 h 2 ) = λ 1 gh 1 + λ 2 gh 2 (λ 1 g 1 + λ 2 g 2 )h = λ 1 g 1 h + λ 2 g 2 h B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 17 / 40
Product Alternative forms Quaternion product may be written as matrix product forms: h 0 h 1 h 2 h 3 g 0 [ ] g 0 h hg = 1 h 0 h 3 h 2 g 1 h0 h h 2 h 3 h 0 h 1 g = T v g 1 2 h v h 0 I + S(h v ) g 2 h 3 h 2 h 1 h 0 g 3 g 3 = F L (h)g or, alternatively, as g 0 g 1 g 2 g 3 h 0 [ ] h 0 g hg = 1 g 0 g 3 g 2 h 1 g0 g g 2 g 3 g 0 g 1 h = T v h 1 2 g v g 0 I S(g v ) h 2 g 3 g 2 g 1 g 0 h 3 h 3 = F R (g)h B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 18 / 40
Quotient Since the quaternion product is anti-commutative we must distinguish between the left and the right quotient or division. Given two quaternions h e p, we define the left quotient of p by h the quaternion q l that satisfies hq l = p while we define the right quotient of p by h the quaternion q r that satisfies q r h = p Hence q l = h h 2 p; q r = p h h 2 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 19 / 40
Inverse Given a quaternion q, in principle one must define the right q 1 r left inverse q 1 l as and the qq 1 l = 1 = (1,0,0,0); q 1 r q = 1 = (1,0,0,0) Since qq = q q = q 2 = q q, one can write q q q = q q q q = 1 = (1,0,0,0) q It follows that right inverse and left inverse are equal q 1 l = q 1 r = q 1 = q q 2 similar to c 1 = c c 2 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 20 / 40
Inverse For a unit quaternion u, u = 1, inverse and conjugate coincide u 1 = u, u = 1 and for a pure unit quaternion q = (0,q v ), q = 1, i.e., a unit vector Inverse satisfies q 1 v = q v = q v. (q 1 ) 1 = q; (pq) 1 = q 1 p 1 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 21 / 40
Unit quaternions Before starting to illustrate the relations between quaternions and rotations, we look closer to the properties of the unit quaternions, that we indicate with the symbol u. A unit quaternion u with u = 1, has an unit inverse and the product of two unit quaternions is still a unit quaternion. We assume that a unit quaternion is represented by a sum of two trigonometric functions u = cosθ + usinθ = (cosθ,usinθ) where u is a unit norm vector and θ a generic angle. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 22 / 40
Unit quaternions Notice the analogy of the formula above with the unit complex number expression c = cosθ + jsinθ The analogy applies also to the exponential expression c = e jθ ; substituting x with uθ in the series expansion of e x and recalling that uu = 1, we have e uθ = cosθ + usinθ = u The relation above shows a formal identity between a unit quaternion and the exponential of a unit vector multiplied by a scalar θ Notice the similarity between u = e uθ and R(u,θ) = e S(u)θ B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 23 / 40
Unit quaternions From the previous relation one obtains the power p of a unit quaternion as u p = (cosθ + usinθ) p = e uθp = cos(θp) + usin(θp) and the logarithm of a unit quaternion logu = log(cosθ + usinθ) = log(e uθ ) = uθ Notice that the anti-commutativity of the quaternion product inhibits to use the standard identities between exponential and logarithms. For instance, e u 1 e u 2 it is not necessarily equal to e u 1+u 2, and log(u 1 u 2 ) is not necessarily equal to log(u 1 ) + log(u 2 ). B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 24 / 40
Quaternions and Rotations Now we relate rotations and unit quaternions: the unit quaternion u = (u 0,u 1,u 2,u 3 ) = (u 0,u) = cosθ + usinθ represents the rotation Rot(u,2θ) around the axis specified by the unit vector u = [ u 1 u 2 u 3 ] T The converse is also true, i.e., given a rotation Rot(u,θ) of an angle θ around the axis specified by the unit vector u = [ u 1 u 2 u 3 ] T, the unit quaternion ( u = cos θ 2,u 1 sin θ 2,u 2 sin θ 2,u 3 sin θ ) ( = cos θ 2 2, usin θ ) = 2 represents the same rotations. cos θ 2 + usin θ 2 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 25 / 40
Quaternions and Rotations We know that a rigid rotation in R 3 is represented by a rotation (orthonormal) matrix R SO(3) R 3 3. We can associate to every rotation matrix R a unit quaternion u and viceversa, indicating this relation as R(u) u. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 26 / 40
Quaternions and Rotations To compute the rotation matrix R(u) given a unit quaternion u = (u 0,u), we use the following relation R(u) = (u0 2 u T u)i + 2uu T 2u 0 S(u) = u0 2 + u2 1 u2 2 u2 3 2(u 1 u 2 u 3 u 0 ) 2(u 1 u 3 + u 2 u 0 ) 2(u 1 u 2 + u 3 u 0 ) u0 2 u2 1 + u2 2 u2 3 2(u 2 u 3 u 1 u 0 ) 2(u 1 u 3 u 2 u 0 ) 2(u 2 u 3 + u 1 u 0 ) u 2 0 u2 1 u2 2 + u2 3 where S(u) is an skew-symmetric matrix. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 27 / 40
Quaternions and Rotations To compute the unit quaternion u = (u 0,u) given a rotation matrix R we use the following relations u 0 = ± 1 2 (1 + r11 + r 22 + r 33 ) u 1 = 1 4u 0 (r 32 r 23 ) u 2 = 1 4u 0 (r 13 r 31 ) u 3 = 1 4u 0 (r 21 r 12 ) B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 28 / 40
Quaternions and Rotations Another alternative set of relations is u 0 = 1 2 (1 + r11 + r 22 + r 33 ) u 1 = 1 2 sgn(r 32 r 23 ) (1 + r 11 r 22 r 33 ) u 2 = 1 2 sgn(r 13 r 31 ) (1 r 11 + r 22 r 33 ) u 3 = 1 2 sgn(r 21 r 12 ) (1 r 11 r 22 + r 33 ) where sgn(x) is the sign function, with sgn(0) = 0. This relation is never singular compared with the previous one that is singular for u 0 = 0 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 29 / 40
Quaternions and Rotations Elementary rotations around the three principal axes R(i, α), R(j, β) and R(k, γ), correspond to the following elementary quaternions R(i,α) u x = (cos α 2, sin α ) 2 (cos, 0, 0 β2, 0, sin β2 ), 0 R(j,β) u y = R(k,γ) u z = ( cos γ 2, 0, 0, sin γ ) 2 It is easy to see that the vectorial base of quaternions correspond to elementary rotations of π around the principal axes i = (0,1,0,0) R(i,π) j = (0,0,1,0) R(j,π) k = (0,0,0,1) R(k,π) B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 30 / 40
Quaternions and Rotations Notice an important fact: while the product among the unit base quaternions gives ii = jj = kk = ijk = ( 1, 0, 0, 0), the product among the associated rotation matrices gives: R(i,π)R(i,π) = R(j,π)R(j,π) = R(k,π)R(k,π) = R(i,π)R(j,π)R(k,π) = I Since I represents a rotation that leaves the vectors unchanged, it seems natural to associate it to positive unit scalar, i.e., the quaternion (1,0,0,0). The apparent discrepancy between the two results can be explained only introducing a most basic mathematical quantity, called spinor, not discussed in the present context B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 31 / 40
Quaternions and Rotations We shall see now some correspondence between quaternion operations and matrix operations Rotation product Given n rotations R 1, R 2,, R n and the corresponding unit quaternions u 1, u 2,, u n, the product corresponds to the product in the shown order. R(u) = R(u 1 )R(u 2 ) R(u n ) u = u 1 u 2 u n B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 32 / 40
Quaternions and Rotations Transpose matrix Given the rotation R(u) and its corresponding unit quaternion u, the transpose matrix (i.e., the inverse rotation) R T corresponds to the conjugate unit quaternion u (i.e., the inverse quaternion) R u R T u B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 33 / 40
Quaternions and Rotations Vector rotation Given a generic vector x, and the corresponding pure quaternion q x = (0,x) = (0,x 1,x 2,x 3 ) and given a rotation matrix R(u) with its corresponding unit quaternion u, the rotated vector y = R(u)x is given by the vectorial part of the quaternion obtained as q y = (0,y) = uq x u where q y = q x B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 34 / 40
The map q x q y = uq x u y = R(u)x that transforms a pure vector into its rotated counterpart, in quaternion form, is called conjugation by u. Notice that the transpose map is equivalent to exchange the order of the conjugation q x q y = u q x u y = R T (u)x Quaternions u and u = u 1 are called antipodal, because they represent opposite points on the 3-sphere of unit quaternions. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 35 / 40
Quaternions and Rotations If we use the homogeneous coordinates to express the vector x x = [ wx 1 wx 2 wx 3 w ] T and the quaternion x is defined as x = (w,wx) the product uxu provides the quaternion y, defined as y = (w,wr(u)x) The resulting vector y, in homogeneous coordinates is therefore ỹ = [ wy 1 wy 2 wy 3 w ] T y = R(u)x B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 36 / 40
Quaternions and Rotations Product matrices Since the bi-linearity property holds for the product between two quaternions, this can be represented by linear operators (i.e., matrices). We recall that the product qp can be expressed in matrix form as qp = F L (q)p This can be interpreted as the left product of q by p. Similarly for the right product pq, expressed as pq = F R (q)p. B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 37 / 40
Quaternions and Rotations We can obtain pq as F R (q )p and where the matrix Q R 4 4 is qpq = F L (q)f R (q )p = Qp Q = F L (q)f R (q ) = q0 2 + q2 1 q2 2 q2 3 2(q 1 q 2 q 3 q 0 ) 2(q 1 q 3 + q 2 q 0 ) 0 2(q 1 q 2 + q 3 q 0 ) q0 2 q2 1 + q2 2 q2 3 2(q 2 q 3 q 1 q 0 ) 0 2(q 1 q 3 q 2 q 0 ) 2(q 2 q 3 + q 1 q 0 ) q0 2 q2 1 q2 2 + q2 3 0 0 0 0 q 2 We observe that the upper left 3 3 matrix of Q equals the matrix R(q) previously defined B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 38 / 40
Infinitesimal rotations and quaternions Quaternions allow to compute angles directly, if they are small. Assume a small angles rotation Rot(dα) and the associated quaternion h = ( h 0 h 1 h 2 h 3 ). We have R(dα) = I + S(dα) = 1 dα 3 dα 2 dα 3 1 dα 1 = r 11 r 12 r 13 r 21 r 22 r 23 dα 2 dα 1 1 r 31 r 32 r 33 hence, considering h 0 = cos dθ 2 1, dα 1 = 1 2 (r 32 r 23 ) = 2h 1 h 0 2h 1 dα 2 = 1 2 (r 13 r 31 ) = 2h 2 h 0 2h 2 dα 3 = 1 2 (r 21 r 12 ) = 2h 3 h 0 2h 3 B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 39 / 40
Quaternions in Aerospace literature In space applications quaternions are used when dealing with satellite orientation control; unfortunately they may be organized in a different way wrt to our conventions: often the real part is the last element of quaternions q = (q 1,q 2,q 3,q 0 ) B. Bona (DAUIN) Quaternions Semester 1, 2016-2017 40 / 40