Game Development Reference

In-Depth Information

9.2.4

Q
UATERNIONS

The best and most widely used representation for orientations is the quaternion.

A
quaternion
represents an orientation with four values, related to the axis and angle

in the following way:

⎡

⎤

cos
2

x
sin
2

y
sin
2

z
sin
2

⎣

⎦

[9.4]

where

⎡

⎤

x

y

z

⎣

⎦

is the axis and
θ
is the angle, as before.

Quaternions are not merely a four-element vector, however; the mathematics is

more exotic. If you are allergic to mathematics, then feel free to skip this explanation

and head for the next section.

You may remember in high school mathematics learning about the square root

−

of

1, the so-called imaginary number (in contrast to real numbers), often written

as i or j. So i
2

1. A complex number is then made up of both a real number and

some multiple of i, in the form
a

=−

b
i. If your mathematical memory is very good,

you might recall drawing complex numbers as coordinates in two dimensions and

deriving lots of their properties geometrically. Complex numbers have a very strong

connection with geometry and in particular with rotations in two dimensions. If you

don't remember, not to worry—quaternions are a little more complex still.

A quaternion is a number of the form
w

+

+

x
i

+

y
j

+

y
k, where i, j, and k are all

imaginary numbers:

i
2

j
2

k
2

=

=

=−

1
.

When all are multiplied together, we also get

−

1:

ijk

=−

1

Together these are the fundamental formulae of quaternion algebra.
1
The second part

of this result means that any two of the three imaginary numbers, when multiplied

1.
The formulae are reputed to have been scratched in the stone of the Bougham Bridge near Dublin

by the discoverer of quaternions, William Rowan Hamilton (the site is now marked by a plaque and the

original carving, if it existed, cannot be seen).