Tutor HuntResources Maths Resources

Quaternions And Rotations

This is a short extract from a Mathematics Essay I wrote as part of my university degree in Mathematics. It is concerned with the Quaternions, which are vectors in 4-dimensional space

Date : 05/07/2013

Author Information

Rajesh

Uploaded by : Rajesh
Uploaded on : 05/07/2013
Subject : Maths

1 Introduction

The quaternions were discovered by Sir William Hamilton is 1843 as he attempted to generalise the complex numbers in a way that would be suitable for 3D space and today they are used throughout the computer graphics and modeling community as a practical and reliable tool for manipulating rotations is 3D space. In this essay i will be introducing the quaternion algebra, which is a four-dimensional division algebra over the real numbers, and will be examining the key properties of quaternions and their relationship to three dimensional rotations that make them a far superior tool for implementing rotations over other classical methods such as the Euler angle representation. I will also explain how quaternions can relate three dimensional coordinate frames to points on the unit hypersphere before finally having a brief look at the Octonions which are an extension of the quaternions.

2 Quaternions and 3D Rotations

In this chapter we discuss quaternions and 3D rotations. A quaternion is an expression q = q0 + q1i + q2j + q3k where q0, q1, q2, q3 ? R and i, j, k are imaginary numbers satisfying Hamilton's celebrated equations i2 =j2 =k2 =ijk=?1 (2.1) from which we can derive the following ij=k jk=i ki=j (2.2)

Definition 2.1. If q = q0 + q1i + q2j + q3k is a quaternion, then we define the real part to be the scalar q0 ? R and the pure part of the quaternion to be q = q1i+q2j +q3k. Then the quaternion is the sum q = q0 + q.

Definition 2.2. We denote the set of all pure quaternions q = (0, q) = q1i + q2j + q3k to be H0

Definition 2.3. The quaternion q = q0 + q1i + q2j + q3k can also be regarded as a four-vector (q0, q1, q2, q3) = (q0, q) ? R4 Using ordinary rules of algebraic multiplication together with (2.1), (2.2) we can define Quaternion Multiplication

2.2 Deriving Quaternion 3D operator One of Hamilton's main motivations for studying quaternions was to find a way to gen- eralise complex numbers that would be applicable to 3D space. In this section we will discuss how quaternions can be used to represent a rotation of a vector in R3. When attempting to define a 3D rotation operator via quaternions, the first obstacles that we encounter is relating quaternions, which can be thought of as an element of R4, to a vectors in R3. There is an isomorphism between R3 and H0 so essentially every vector v ? R3 corresponds to the pure quaternion v = 0 + v ? H0

Proposition 2.7 For any unit quaternion q = q0 + q, we can associate an angle ? andunitvectorn^?R3 ,suchthatq=cos?+n^sin? Proof. Since q = q0 + q is a unit quaternion, this implies (q0)2 + (q)2 = 1 Then there exists some angle 0 ? ? < ? for which cos2 ? = q02 sin2 ? = ?q?2 Define unit vector n^ which represents direction of q by n^ = q = q ?q? sin ? Thus q = q0 + q = cos? + n^ sin ?

Now that we can associate angles to quaternions and relate them to vector in R3, we proceed to state the main theorem of this section 3

Theorem 2.8 For any quaternion q = q0 + q = cos? + n^sin? and ?v ? R3 the actions of the operator Lp(v) = qvq (2.6) on v can be interpreted geometrically as a rotation of v through 2? about the axis of rotation q.

Before we prove Theorem 2.8, we examine some properties of the rotation operator (2.6) which will lead us to conclude that it is well defined. Proposition 2.9 When we input a vector v ? R3 into our operator Lp(v) = qvq, our output is also a vector in R3.

Proof. Let v ? R3, corresponding to v = 0 + v ? H0, be our input vector. Then letting w = qvq, w = qvq = (q0 +q)(0+v)(q0 ?q) = (?q·v+q0v+q×v)(q0 ?q) = (2q02?1)v+2(q·v)q+2q0(q×v) (2.7) w is a pure quaternion (since the real part of w is equal to 0) and hence it corresponds to a vector w ? R3

Proposition 2.10 Length of a vector v ? R3 remains unchanged under rotation by (2.6). Proof. Since q is a unit quaternion N (w) = N (qvq) = N(q) · N(v) · N(q) = 1·N(v)·1 = N(v) (2.8)

Lemma 2.11 For any vectors v1, v2 ? R3, ?, ? ? R, 4 Lq(?v1 + ?v2) = ?Lq(v1) + ?Lq(v2) Hence, the quaternion operator Lp(v) = qvq is linear.

Proof. Lq(?v1 + ?v2) = = (?qv1 + ?qv2)q = ?qv1q + ?qv2q = ?Lq (v1 ) + ?Lq (v2 ) (2.9) q(?v1 + ?v2)q We will now prove Theorem 2.8.

Proof. (Theorem 2.8) Let q = q0 +q = cos?+n^sin? be a unit quaternion where n^ = q is the direction of ?q? the quaternion. For any given vector v ? R3, we resolve v into two orthogonal components: v = a+m where a is the component of v along the vector part of q, and n is the component of v normal to the vector part of q. Hence, when considering the effects of the rotation operator on a vector v ? R3 we can consider the effects on a and on m. Now we consider the effects of rotation operator (2.6) on the component m: Lq(m) = (q02 + ?q?2)m + 2q0(q × m) = (q02 + ?q?2)m + 2q0?q?(n^ × m) Using the trigonometric form of our quaternion q, we can rewrite this Lq(m) = (cos2??sin2?)m+(2cos?sin?)(n^×m) = cos 2?m + sin 2?(n^ × m) Substituting n^ × m = m^ , our equation becomes Lq (m) = cos 2?m + sin 2?m^ (2.10) (2.11) Viewing the components of Lq(m) in [Figure 1], we can verify that the quaternion operator rotates m through angle 2? about q where q as an axis: 5 Hence Lq(v) = Lq(a + m) = Lq(a) + Lq(m) = a+l=w (2.12) Where l = Lq (m) = cos 2?m + sin 2?m^ We have therefore shown that w = a+l can be viewed as the vector v rotated through angle 2? about q, where q acts as an axis. Corollary 2.12 The composition of two quaternion operators Lq(v) = qvq and Lr(v) = rvr is a rotation operator.

Proof. Lq (Lr (v)) = q[Lr (v)]q = q[rvr]q = (qr)(v)(qr) = Lqr(v) (2.13) Before we continue with our analysis of the 3D quaternion operator, we briefly consider the two different geometric interpretations we can have of this quaternion operator. There is the obvious interpretation of Lq(v) = qvq as being a rotation of a vector v by angle 2? about q as an axis. Equivalently, we can think of Lq(v) = qvq as being a rotation of the co-ordinate frame through angle 2? about the same axis q. In the next chapter we will be addressing co-ordinate frame rotations in more detail.

2.3 Quaternions and Euler Angles As a demonstration of one of the advantages of using quaternions for 3D rotations, we will compare them with the Euler angles representation. One way in which we can treat a rotation in 3D space is as sequences of axis-angle rotations. A sequence of 3 axis-angle rotations is called the Euler angle representation (for example, a rotation about the x axis followed by another about the y axis and then about the z axis). We can denote a sequence of rotations by writing the axes around which we rotate in order. For example XY Z denotes a rotation about the x axis, followed by a rotation about the y axis, followed by a rotation about the newly formed z axis. The existence of such a sequence of rotations comes from Euler's theorem of rotations:

Theorem 2.14 (Euler's Theorem of Rotations) Any two orthonormal co-ordinate frames can be related by a sequence of rotations about co-ordinate axes, where no two successive rotations may be about the same axis. One commonly used sequence is ZY Z which has explicit matrix form: ?cos? ?sin? 0??1 0 0 ??cos? ?sin? 0? Rzyz(?,?,?) = ? sin? cos? 0 ?? 0 cos? cos? ?? sin? cos? 0 ? 0 0 1 0sin?cos? 0 0 1 ? cos?cos?cos??sin?sin? ?sin?cos??cos?cos?sin? cos?sin? ? = ? sin?cos?cos?+cos?sin? cos?cos??sin?cos?sin? sin?sin? ? 2q0 q1 0 ?sin?cos? sin?sin? cos? Although it may seem more convenient to compute rotations as a sequence of 3 axis angle rotations, Euler angle representation can experience a phenomenon called gimbal 7 (2.15) lock which in effect is the loss of one degree of freedom in three-dimensional space that occurs when two of our three axes become aligned. It is a major problem for computer programmers but by parametrising the rotation matrix via quaternions we can avoid gimbal lock. Using our Euler angle representation defined in (2.15) we can demonstrate how we lose a degree of freedom in 3D space. Consider the case when ?,? ? [??,?] but ? ? [0,?]. When ? = 0 and ? ? cos?cos??sin?sin? ?sin?cos??cos?sin? 0 ? Rzyz =? sin?cos?+cos?sin? cos?cos??sin?sin? 0 ? 001 No matter what value of ? or ? we take, the rotation remains fixed in the z -direction, and hence we have lost a degree of freedom (the ability to rotate freely about the z - axis) The corresponding quaternion for the rotation matrix defined by (2.15) is given by: q0 = cos?cos1(?+?) 22 q1 = sin?sin1(???) 22 q2 = sin?cos1(???) 22 q3 = sin?sin1(?+?) 22 This system does not experience gimbal lock because it explains the rotation in one motion (i.e. rotation of a certain angle about a certain direction) while the Euler angle form explains it in three successive rotations.

This resource was uploaded by: Rajesh