Game Development Reference
In-Depth Information
Quaternions, like vectors, have a magnitude:
= w 2 + v
v = w 2 + x 2 + y 2 + z 2 .
q
·
Quaternions of magnitude 1, or unit quaternions, have properties that make them
useful for representing rotations.
Like matrices, quaternions have a multiplicative identity, which is (1 , 0 ).There
is also the notion of a multiplicative inverse. For a unit quaternion ( w, v ),thein-
verse is equal to ( w,
v ). We can think of this as rotating around the opposing
axis to produce the opposite rotation. In general, the quaternion inverse is
1
w 2 + x 2 + y 2 + z 2 ( w,
q 1 =
v ) .
1.5.3 Vector Rotation
If we consider a rotation of angle θ around an axis r , we can write this as a
quaternion:
q =(cos( θ/ 2) , sin( θ/ 2) r ) .
It can be shown that this is, in fact, a unit quaternion.
We can use a quaternion of this form to rotate a vector p around r by θ by
using the formulation
p rot = qpq 1 .
Note that in order to perform this multiplication, we need to rewrite p as a quater-
nion with a zero-valued w term, or (0 , p ).
This multiplication can be expanded out and simplified as
p rot =cos θ p +[1 cos θ ]( r · p ) r +sin θ ( r × p ) ,
which as we see is the same as Equation (1.3) and demonstrates that quaternions
can be used for rotation.
1.5.4 Matrix Conversion
It is often useful to convert a quaternion to a rotation matrix, e.g., so it can be
used with the graphics pipeline. Again, assuming a unit rotation quaternion, the
following is the corresponding matrix:
1 2 y 2
2 z 2
2 xy − 2 wz
2 xz +2 wy
.
2 xy +2 wz
1 2 x 2
2 z 2
2 yz − 2 wx
R q =
2 x 2
2 y 2
2 xz
2 wy
2 yz +2 wx
1