Game Development Reference
In-Depth Information
2.9.2 Geometric Interpretation
In 2D, if we draw a unit vector with the tail at the origin, the head of
the vector will touch a unit circle centered at the origin. (A unit circle
has a radius of 1.) In 3D, unit vectors touch the surface of a unit sphere.
Figure 2.16 shows several 2D vectors of arbitrary length in gray, beneath
their normalized counterparts in black.
Notice that normalizing a vector makes some vectors shorter (if their
length was greater than 1) and some vectors longer (if their length was less
than 1).
2.10
The Distance Formula
We are now prepared to derive one of the oldest and most fundamental
formulas in computational geometry: the distance formula. This formula
is used to compute the distance between two points.
First, let's define distance as the length of the line segment between the
two points. Since a vector is a directed line segment, geometrically it makes
sense that the distance between the two points would be equal to the length
of a vector from one point to the other. Let's derive the distance formula
in 3D. First, we will compute the vector d from a to b . We learned how to
do this in 2D in Section 2.7.3. In 3D, we use
2
3
b x
− a x
4
5
d = b a =
b y
− a y
.
b z
− a z
The distance between a and b is equal to the length of the vector d ,
which we computed in Section 2.8:
d x 2 + d y 2 + d z 2 .
distance ( a , b ) = d =
Substituting for d , we get
distance ( a , b ) = b a =
(b x − a x ) 2 + (b y − a y ) 2 + (b z − a z ) 2 .
The 3D distance formula
Thus, we have derived the distance formula in 3D. The 2D equation is even
simpler:
distance ( a , b ) = b a =
(b x − a x ) 2 + (b y − a y ) 2 .
The 2D distance formula
Let's look at an example in 2D:
distance
5
0
,
−1
8
=
(−1 − 5) 2 + (8 − 0) 2
=
(−6) 2 + 8 2 =
100 = 10.
Search WWH ::




Custom Search