Game Development Reference
In-Depth Information
As Figure 6 shows, vector subtraction returns a vector from the head of
v
to the head of
u
. If we interpret the components of
u
and
v
as the
coordinates of points, we can use vector subtraction to find the vector
from one point to another. This is a very convenient operation because
we will often want to find the vector describing the direction from one
point to another.
Scalar Multiplication
We can multiply a vector by a scalar, as the name suggests, and this
scales the vector. This operation leaves the direction of the vector
unchanged, unless we scale by a negative number, in which case the
direction is flipped (inverted).
k
u
, ,
The
D3DXVECTOR3
class provides a scalar multiplication operator:
D3DXVECTOR3 u(1.0f, 1.0f, -1.0f);
D3DXVECTOR3 scaledVec=u*10.0f; // = (10.0f, 10.0f, -10.0f)
ku
ku
ku
x
y
z
Dot Products
The dot product is one of two products that vector algebra defines. It is
computed as follows:
u
v
u
v
u
v
u
v
s
x
x
y
y
z
z
The above formula does not present an obvious geometric meaning.
Using the law of cosines, we can find the relationship
uv uv
cos
, which says that the dot product between two vectors
is the cosine of the angle between them scaled by the vectors' magni-
tudes. Thus, if both
u
and
v
are unit vectors, then
u·v
is the cosine of
the angle between them.
Some useful properties of the dot product:
If
u·v
= 0, then
u
v
.
If
u
·
v
> 0, then the angle,
, between the two vectors is less than
90 degrees.
If
u
·
v
< 0, then the angle,
, between the two vectors is greater
than 90 degrees.
Note:
symbol means “orthogonal,” which is synonymous with
the term “perpendicular.”
The
Search WWH ::
Custom Search