Game Development Reference

In-Depth Information

together, give us the third. But beware: quaternion mathematics isn't commutative.

In other words,
ab

=

ba
, and in particular,

ij

=−

ji

=

k

jk

=−

kj

=

i

ki

=−

ik

=

j

by definition.

With these laws we can combine quaternions by multiplication:

(w
1
+

x
1
i

+

y
1
j

+

z
1
k
)

×

(w
2
+

x
2
i

+

y
2
j

+

z
2
k
)

=

(w
1
w
2
−

x
1
x
2
−

y
1
y
2
−

z
1
z
2
)

+

(w
1
x
2
+

x
1
w
2
−

y
1
z
2
−

z
1
y
2
)
i

+

(w
1
y
2
−

x
1
z
2
+

y
1
w
2
−

z
1
x
2
)
j

+

(w
1
z
2
+

x
1
y
2
−

y
1
x
2
+

z
1
w
2
)
k

and if the original two quaternions represent rotations according to equation 9.4,

then the resulting quaternion is equivalent to the two rotations combined. I will write

quaternions using the format
θ

ˆ

and in a four-element vector format to show their

components:

⎡

⎣

⎤

⎦

w

x

y

z

θ

ˆ

=

Quaternions have four degrees of freedom to represent the three degrees of free-

dom of rotation. Clearly we have an extra degree of freedom that we need to constrain

away.

In fact, for all rotations equation 9.4 implies that the magnitude of the quaternion

is exactly 1. We calculate the magnitude of the quaternion in exactly the same way as

we did for a three-element vector, by using a four-component version of Pythagoras's

theorem:

w
2

+

x
2

+

y
2

+

z
2

To make sure that a quaternion always represents a rotation, we therefore need to

make sure that it has unit length:

w
2

+

x
2

+

y
2

+

z
2

=

1

We do this using a procedure identical to normalizing a vector, but operating on

all four components of the quaternion rather than on the three values in a vector.