Game Development Reference
In-Depth Information
dicular to n , which is a much simpler 2D problem. To do this, we separate
v into two vectors, v and v , which are parallel and perpendicular to n ,
respectively, such that v = v + v . (We learned how to do this with the
dot product in Section 2.11.2.) By rotating each of these components indi-
vidually, we can rotate the vector as a whole. In other words, v
.
Since v is parallel to n , it will not be affected by the rotation about n . In
other words, v
+ v
= v
= v . So all we need to do is compute v
, and then we
have v
, we construct the vectors v , v , and
an intermediate vector w , as follows:
= v + v
. To compute v
The vector v is the portion of v that is parallel to n . Another way
of saying this is that v is the value of v projected onto n . From
Section 2.11.2, we know that v = ( v n ) n .
The vector v is the portion of v that is perpendicular to n . Since
v = v + v , v can be computed by v v . v is the result of
projecting v onto the plane perpendicular to n .
The vector w is mutually perpendicular to v and v and has the
same length as v . It can be constructed by rotating v 90 o about
n ; thus we see that its value is easily computed by w = n × v .
These vectors are shown in Figure 5.5.
How do these vectors help us
compute v
? Notice that w and
v form a 2D coordinate space,
with v as the “x-axis” and w
as the “y-axis.” (Note that the
two vectors don't necessarily have
unit length.) v
is the result of
rotating v
in this plane by the
angle θ. Note that this is almost
identical to rotating an angle into
standard position. Section 1.4.4
showed that the endpoints of a
unit ray rotated by an angle θ are
cosθ and sinθ. The only differ-
ence here is that our ray is not a
unit ray, and we are using v and
w as our basis vectors. Thus, v
Figure 5.5
Rotating a vector about an arbitrary axis
can be computed as
v
= cosθ v + sinθ w .
Search WWH ::




Custom Search