Game Development Reference
In-Depth Information
proach that lets you keep the advantages rotation matrices have to offer, but at a cheaper
price. That alternative, quaternions, is the subject of the next section.
Quaternions
Quaternions are somewhat of a mathematical oddity. They were developed over 100
years ago by William Hamilton through his work in complex (imaginary) math but have
found very little practical use. A quaternion is a quantity, kind of like a vector, but made
up of four components. It is typically written in the form:
q = q 0 + q x i + q y j + q z k
A quaternion is really a four-dimensional quantity in complex space and, unfortunately,
does not lend itself to visualization. Don't worry, though: our use of quaternions to
represent orientation in three dimensions does allow us to attach a physical meaning to
them, as you'll see in a moment.
Of particular interest to us is what's known as a unit quaternion that satisfies the fol‐
lowing:
q 0 2 + q x 2 + q y 2 + q z 2 = 1
This is analogous to a normalized, or unit, vector.
You can also write a quaternion in the form q = [ q 0 , v ], where v is the vector, q x i + q y j
+ q z k , and q 0 is a scalar. In the context of rotation, v represents the direction in which
the axis of rotation points. For a given rotation, θ, about an arbitrary axis represented
by the unit vector u , the representative quaternion can be written as follows:
q = [cos(θ/2) , sin(θ/2) u ]
This is illustrated in Figure 11-3 for an arbitrary rigid body rotating about an axis passing
through its center of gravity. The rigid body rotates through an angle θ from the position
shown in light gray to the position shown in dark gray. Here, the unit vector u is the
vector v normalized to unit length.