7.1 Introduction

William Rowan Hamilton's discovery of quaternions on an October morning in 1843 is one of the best documented scientific events in history. "Quaternions sprang to light, or life, full-grown," wrote Hamilton in his memoirs. He was "walking with Lady Hamilton over Brougham Bridge", now known locally as Quaternion Bridge, in Dublin. Lady Hamilton was talking to her husband, relating some private thoughts of deep personal significance when "Suddenly the galvanic circuit of thought closed, and the basic quaternion equations presented themselves to my mind, exactly as I have used them ever since." At the end of the last chapter quaternions were introduced to you as sums of scalars and bivectors in 3-D space. This is not how Hamilton defined them in 1843, one good reason being that nobody knew about bivectors then. Even today, quaternions are usually presented as an isolated algebraic system, disconnected from general linear algebra, and restricted in their application to 3-D space. In this chapter we too will treat quaternions as an isolated system for calculating 3-D rotations. This way you can get the main points of quaternion algebra in one chapter without being overwhelmed by huge bizarre spaces of bivectors and other exotica which are less directly relevant to your work.

7.2 Definitions

In discussing quaternions we use the names i, j and k for the standard (right handed, orthonormal) basis vectors. We forget that we ever dreamed of bivectors, and regard a quaternion as the sum of a scalar and a vector:

q = q0 + q1i + q2j + q3k. (7.1)

(Since vectors and bivectors in 3-D space are so similar in their properties, we still end up with the correct formula for rotating vectors). Quaternions form a 4-D vector space with addition and scalar multiplication defined in the obvious way. Vectors in 3-D space can be regarded as quaternions with the scalar component q0 = 0; if you remove the scalar component of a quaternion q, what's left is called the vector part of q, and is written either Vq or q (boldface).

In addition to the usual vector space operations, there is a noncommutative, bilinear, associative operation called quaternion multiplication (really a special case of Clifford multiplication) which is defined by the rules:

i2 = j2 = k2 = -1 (7.2)
ij = -ji = k      jk = -kj = i         ki = -ik = j

These are the basic quaternion equations which sprang into Hamilton's mind full-grown, and which he immediately carved with a penknife into the stone of Brougham Bridge. The easiest way to remember these rules is to write i, j and k around a circle as we did for the cross product in Chapter 2. Harder to remember, but faster for hand computation, is the following formula for the product r = pq, with can be derived from (7.2):

r0 = p0q0 - p1q1 - p2q2 - p3q3
r1 = p0q1 + p1q0 + p2q3 - p3q2
r2 = p0q2 + p2q0 - p1q3 + p3q1
r3 = p0q3 + p3q0 + p1q2 - p2q1. (7.3)

The magnitude of a quaternion is |q| = (q02 + q12 + q22 + q32).5. Every nonzero quaternion has a unique inverse q-1 such that qq-1 = q-1q = 1. It is not hard to verify that the inverse of q is

q-1 = ( q0 - q1 - q2 - q3 ) / |q|2 = (q0 - q) / |q|2 (7.4)

In particular, for the unit quaternions which we will mainly be using:

q-1 = q0 - q (7.5)

Finally, two definitions will pave the way for the application of quaternions to rotations. We note that a unit quaternion can always be written in the form

cosØ + n1sinØ + n2sinØ + n3sinØ. (7.6)

where n = (n1, n2, n3) is a unit vector. Proof: The magnitude of the vector part of the quaternion, q, must be between -1 and 1 (inclusive), and so there must be some angle Ø, such that |q| = sinØ. Thus q can be written q = |q|n = sinØ n, where n is q normalized. The sum of squares of the quaternion components must be |q| = 1, and so q02 = 1 - |q|2 = 1 -sin2Ø = cos2Ø. ||| Here n is called the axis, the angle, of the quaternion. A non-unit quaternion also has an angle and axis, which are obtained by normalizing it and computing the angle and axis of the resulting unit quaternion.

7.3 Quaternions and Rotations

I. The conjugation operation, qvq-1, rotates the vector v about the axis of q (according to the right hand rule) through twice the angle of q. This holds for any (3-component) vector v and any nonzero quaternion q, though we'll almost always use unit quaternions in our calculations.

Example 7.1. If you want to rotate the vector v = (1, 2, 0) = i + 2j 60° rightward about a vertical axis (parallel with k), you first construct the relevant unit quaternion. The axis n of the quaternion must be vertical, and must point down in order to represent a rightward rotation by the right hand rule (because when you point your right thumb down, your fingers curl round to the right); thus n = -k = (0, 0, -1). The angle Ø of the quaternion must be half the desired rotation angle, ie Ø = 60° / 2 = 30°. The scalar part of the quaternion, q0, is therefore cosØ = cos30° = .87. The vector part, q, is sinØ n = .5n = (0, 0, -.5). The quaternion as a whole can then be written (.87, 0, 0, -.5) or .87 - .5k. The rotated vector is qvq-1 = (.87 - .5k)(i + 2j)(.87 + .5k) = (.87i + 1.74j - .5ki - kj)(.87 + .5k) = (1.87i + 1.24j)(.87 + .5k) = 1.63i + .94ik + 1.08j + .62jk = 2.25i + .14j = (2.25, .14, 0). You can draw a picture to verify that this answer is correct, but note also that there are a number of quick checks you can do to see that the result makes sense: 1. The product qvq-1 is a 3-component vector (i.e. the scalar component is 0), 2. The vectors v and qvq-1 have the same vertical component, as you would expect for a rotation about a vertical axis, and 3. You can see that the magnitude of qvq-1 is the same as that of v.

Problem 7.1. Use quaternions to rotate the vector j 90° up and to rotate the vector (4,0, 1) 40° left and clockwise about an axis tilted 30° forward from k in the ik plane.

A peculiar feature of quaternions is that infinitely many of them correspond to any given rotation. To see this, we must first observe that, if s is any nonzero scalar and q any nonzero quaternion, then (sq)-1 = q-1 / s, because (sq)(q-1 / s) = s(qq-1)/ s = s / s = 1. Now we can prove that, if q is a nonzero quaternion representing some rotation, then any nonzero scalar multiple sq represents the same rotation, because (sq)v(sq)-1 = (sq)v(q-1) / s = s(qvq-1) / s = qvq-1. In other words, all nonzero scalar multiples of any quaternion represent the same rotation. Of the infinity of quaternions representing any rotation, two will be unit quaternions; (given one, you get the other my multiplying by -1). For our computations, we usually use the unit quaternion with the scalar component q0 > 0. When we talk about the quaternion of eye position, we will always mean the unit quaternion with a nonnegative scalar component.

II. Quaternion multiplication can be used to compose rotations. If quaternions q' and q'' represent rotations R1 and R2 respectively, then the quaternion product q''q' represents the composition R2 R1. Note that the quaternion representing the second rotation is on the left side in the product. If you mix up the order, you will get the wrong composite rotation, thanks to noncommutativity.

Example 7.2. The three rotations, 180° clockwise, 180° down and 180° left are represented by the quaternions i, j and k. The composite of all three rotations in this order is kji = -ii = 1 = (1, 0, 0, 0), which has scalar component 1 and therefore angle = arccos(1) = 0°. That is, the composite of these three is the null rotation, as you can easily verify. Note that if you compose the three rotations 180° left, 180° down and 180° clockwise in this order, you again get the null rotation (check this with a teddy bear). If we compose the rotations using quaternions, we obtain the product ijk = kk = -1, instead of 1. This answer is correct, because both 1 and -1 represent the null rotation.

Problem 7.2. Suppose an experimental subject is looking straight ahead, i.e. g = i. a. Compute the gaze vector and the quaternion of the subject's eye position after two rotations, 30° left and 20° down. b. Do the same for the same rotations in the opposite order. c. Do the same for the eye position attained by rotating first 30° left and then 20° up about an axis orthogonal to the gaze line (which is directed 30° left after the first rotation).

III. Quaternion powers can be used to iterate or "divide" rotations. For example, if q represents a rotation of 20° right, then q2 represents a rotation of 40° right and q1/2 (the square root of q) represents a rotation of 10° right. To compute a power, we express the quaternion in terms of its axis and angle: if q = |q|(cosØ + nsinØ) then

qx = |q|x [ cos(xØ) + nsin(xØ) ]. (7.7)

Note that if x = -1, this equation reduces to Formula (7.4) for quaternion inversion. Note also that all powers of a given quaternion have the same axis (n) and that all powers of a unit quaternion are also unit quaternions.

IV. Quaternion conjugation can be used to change the coordinate system of a rotation. This very important application recurs throughout our work. For example, suppose r is a quaternion representing a rotation of 30° left, and q represents a rotation of 20° down (so that the vector part of q is jsin10°). Observe what happens when we conjugate q with r:

rqr-1 = r(q0 + q)r-1
= rq0r-1 + rqr-1
= q0rr-1 + rqr-1
= q0 + rqr-1. (7.8)

What happens is that the scalar component q0 is unchanged, while the vector part gets rotated 30° left. It follows that the angle of the quaternion is unchanged, but the axis rotates, so that rqr-1 represents a rotation of 20° down about an axis rotated 30° left from j.

It will be very useful to consider a simple example of this principle in preparation for the more complicated applications in the next section. We'll use the quaternions r and q defined above and apply Formula (7.8) to Problem 7.2. In part a, you were asked to compute the final eye position after two eye rotations: 30° left followed by 20° down. Since quaternion r represents the first rotation and q the second, the overall rotation in part a is qr. In part b, the order is reversed, giving rq. In part c, the first rotation is r and the second is a rotation, call it p, of 20° down about an axis tilted 30° left. You can either work out this quaternion from scratch: p = cos10° + sin10°(-.5, .87, 0), or you can observe that p = rqr-1, and so the overall rotation is pr = rqr-1r = rq; i.e. the rotation is the same as in part b. I have described this as "changing the coordinate system" of a rotation because q is a vertical rotation in head or space coordinates while p = rqr-1 is a vertical rotation in eye coordinates. You should think about this example constantly, for days on end if necessary, until the galvanic circuit of thought closes and the equations and their physical meaning are clear.

The main properties of quaternions are summarized in the list below:

QP1. pq is not equal to qp
QP2. p(q + r) = pq + pr
QP3. (sp)q = p(sq) = s(pq)
QP4. q-1 = (q0 - q) / |q|2
QP5. p(qr) = (pq)r
QP6. qvq-1 rotates a vector
QP7. pq composes two rotations
QP8. qx rotates x times as far as q about the same axis
QP9. rqr-1 rotates the rotation axis of q