Game Development Reference
In-Depth Information
/ /
Next
v e r t e x ,
p l e a s e
p
=
c ;
}
/ /
Normalize
t h e
r e s u l t
and
r e t u r n
i t
r e s u l t . n o r m a l i z e ( ) ;
r e t u r n
r e s u l t ;
}
Listing 9.5
Computing the best-fit plane normal for a set of points
The best-fit d value can be computed as the average of the d values for
each point:
n
n
d = 1
n
n ) = 1
n
( p i
p i
n .
Computing the best-fit
plane d value
i=1
i=1
9.5.4
Distance from Point to Plane
It is often the case that we have a plane and a point q that is not in the
plane, and we want to calculate the distance from the plane to q , or at
least classify q as being on the front or back side of the plane. To do this,
we imagine the point p that lies in the plane and is the closest point in the
plane to q . Clearly, the vector from p to q is perpendicular to the plane,
and thus is of the form a n , as shown in Figure 9.14.
Figure 9.14
Computing the
distance between a
point and a plane
If we assume the plane normal n is a unit vector, then the distance
from p to q (and thus the distance from the plane to q ) is simply a. This
is a signed distance, which means that it will be negative when q is on the
back side of the plane. What's surprising is that we can compute a without
knowing the location of p . We go back to our original definition of q and
then perform some vector algebra to eliminate p :
 
Search WWH ::




Custom Search