Game Development Reference
In-Depth Information
tive angle about the axis A to be that which performs a counterclockwise rotation
when the axis A is pointing toward us.
First, we will find a general formula for rotations in two dimensions. As
shown in Figure 4.2, we can perform a 90-degree counterclockwise rotation of a
2D vector P in the x-y plane by exchanging the x and y coordinates and negating
the new x coordinate. Calling the rotated vector Q , we have
Q . The
vectors P and Q form an orthogonal basis for the x-y plane. We can therefore
express any vector in the x-y plane as a linear combination of these two vectors.
In particular, as shown in Figure 4.3, any 2D vector
=−
P
,
P
y
x
P that results from the rota-
tion of the vector P through an angle θ can be expressed in terms of its compo-
nents that are parallel to P and Q . Basic trigonometry lets us write
PP
′ =
cos
θ
+
Q
sin
θ
.
(4.12)
This gives us the following expressions for the components of
P .
=
PP θ P θ
P
cos
sin
x
x
y
=
P θ P θ
cos
+
sin
(4.13)
y
y
x
We can rewrite this in matrix form as follows.
cos
θ
sin
θ
=
P
(4.14)
P
sin
θ
cos
θ
The 2D rotation matrix in Equation (4.14) can be extended to a rotation about
the z axis in three dimensions by taking the third row and column from the identi-
ty matrix. This ensures that the z coordinate of a vector remains fixed during a
rotation about the z axis, as we would expect. The matrix
()
R
z θ
that performs a
rotation through the angle θ about the z axis is thus given by
cos
θ
sin
θ
0
()
R
θ
=
sin
θ
cos
θ
0
.
(4.15)
z
0
0
1
()
()
Similarly, we can derive the following 3
×
3
matrices
R
x θ
and
R
y θ
that
perform rotations through an angle θ about the x and y axes, respectively: