Major points of these notes: Quaternion Rotations AUI Course Denbigh Starkey. What I will and won t be doing. Definition of a quaternion and notation 3 3. Using quaternions to rotate any point around an arbitrary axis 5 4. Quaternion rotation example 6 5. Another rotation example 8 6. Multiple rotations 9
. What I will and won t be doing In these notes I ll be defining quaternions, and I ll be showing how they can be used to rotate a point (and hence an object) around an axis. I won t, however, be covering any of the underlying mathematics of quaternions, except as is necessary to perform the calculations. So, for example, I ll state that the inverse of a unit quaternion (s, v) is (s, -v), but won t prove that this is correct, and I won t discuss the inverse of a general (non-unit) quaternion. I ll cover these in the next set of notes, along with the rest of the underlying mathematics.
. Quaternion definition and quaternion notation Quaternions, which were first defined by Hamilton in three papers (or at least these are the first three that I can find) in 844 and 845, are essentially multi-dimensional complex numbers. Whereas a standard complex number has a scalar component and an imaginary component, with quaternions the imaginary part is an imaginary vector based on three imaginary orthogonal axes. All of that sounds weird, but it turns out that quaternions are both relatively simple and very effective for rotations. A quaternion is defined using a scalar component, s, and an imaginary vector component v = (iv, jv, kv 3 ). I ll write this in three equivalent ways: q = (s, v) q = (s, v, v, v 3 ) q = (s + iv + jv + kv 3 ) and I ll switch between these three forms without warning, as I need. If the scalar component, s, is zero, then the quaternion is called a pure quaternion. First I need to define i, j, and k. They are imaginary orthogonal unit vectors which satisfy the following equations. i = j = k = - ij = k = -ji jk = i = -kj ki = j = -ik We ll also need a couple of quaternion properties, the magnitude of a quaternion and how to multiply two quaternions. The size, or magnitude, of q = (s, v) is given by q = s + v. Quaternion multiplication is defined in the obvious way. I.e., q q = (s + v i + v j + v 3 k) (s + v i + v j + v 3 k) = (s s + s v i + s v j + s v 3 k + v s i + + v 3 v kj + v 3 v 3 k ). 3
Then we just have to substitute k for ij, - for i, etc., in these 6 terms and we are done. We can also, by rearranging the terms, define quaternion multiplication using dot product and cross product to simplify the result. For example, the scalar terms in the product above will come from s = s s + v v i + v v j + v 3 v 3 k = s s (v v + v v + v 3 v 3 ) = s s v. v from first replacing the square terms with - and then using the definition of dot product. Similarly, we can collect other terms, and get: q q = (s s v. v, s v + s v + v! v ) 4
3. Using quaternions for rotations around an arbitrary axis To rotate a point (x, y, z) by an angle θ counterclockwise around an arbitrary avis through the origin which is defined by a unit vector u, we compute where P = q P q - P = (0, x, y, z) is a pure quaternion whose imaginary part is the point, q = (cos(! ), sin(! )u), and q - = (cos(! ), -sin(! )u). The three quaternions on the right hand side of the equation for P are multiplied using quaternion multiplication. The new quaternion P will, like P, be pure (i.e., its real component will be zero), and its imaginary components will contain the transformed point. In the next section I ll give an example of this. 5
4. Quaternion Rotation Example Assume that we want to rotate the Cartesian point (,, -) 90 around the Z axis, which is defined by the unit vector (0, 0, ). Since Z will be fixed, this is a simple D rotation, and we can easily see that the new point should be (-,, -). Since sin(45 ) = cos(45 ) =, we have and so q = (, (0, 0, )) = (, 0, 0, ) P = (0,,, -) q - = (, - (0, 0, )) = (, 0, 0, - qp = ( + k) (i + j k) ( + k) (i +j k) = = = = (i + j k + ki + kj k ) (i + j k + j i + ) ( i + 3j k) ) qpq - = ( i + 3j k) ( k) = ( k i + ik + 3j 3jk k + k ) = ( k i j + 3j 3i k ) = (0 4i + j k) = (0, -,, -) P, the transformed point, is the imaginary part of this pure quaternion, which is (-,, -), as expected. As an alternative to the individual multiplications, I could have (twice) used the definition on quaternion multiplication that uses dot and cross products given above, q q = (s s v. v, s v + s v + v! v ) Using that approach I would have had 6
qpq - = (, (0, 0, )) (0, (,, -)) (, (0, 0, -)) = (0 (-), (,, -) + (-,, 0)) (, (0, 0, -)) = (, (-, 3, -)) (, (0, 0, -)) = (, (0, 0, -) + (-, 3, -) + (-3, -, 0)) = (0, (-4,, -)) which is once again the point (-,, -). 7
5. Another rotation example Now I ll try rotating the point ( 3,, 0) counterclockwise 60 around the Z axis. Since cos(30 ) = 3 and sin(30 ) =, we have: P = ( 3, 0, 0, ) (0, 3,, 0) ( 3, 0, 0, - ) = 4 ( 3 + k) ( 3 i + j) ( 3 k) = 4 (3i + 3 j + 3 ki + kj) ( 3 k) = 4 (3i + 3 j + 3 j i) ( 3 k) = (i + 3 j) ( 3 k) = ( 3 i ik + 3j 3 jk) = ( 3 i + j + 3j 3 i) = j = (0, 0,, 0) So the transformed point is (0,, 0). A simple diagram should persuade you that this is correct: ( 3,, 0) 60 30 8
6. Multiple rotations Usually we won t be doing a single rotation, but will be doing a series of rotations in an animation. E.g., say that we have a sequence of rotations defined, in time order, by the quaternions q, q,, q n, We ll need to compute P = q n q q Pq - q - q n - Fortunately quaternion multiplication is associative, and also q - q - q n - = (q n q q ) -. So we just use repeated multiplications to compute a single combined unit quaternion q = q n q q = (s, v) and the inverse will then be (s, -v). 9