10.4 Point to Polyhedron 393
We know that if P is not contained within the tetrahedron, then it will have
a nonnegative distance to one, two, or three faces. Thus, we can calculate the dot
product
n
i
· (P −V
3−i
)
for i = 0, 1, 2, 3. By looking at the signs of all four dot products, we can determine
which (if any) faces the point is outside of; we then can compute the distance to
each face for which the dot product is nonnegative, and take the minimum of these
distances to be our final solution.
Point to Convex Polyhedron
If the convex polyhedron is strictly convex (no faces share a plane), then an approach
can be taken that is analogous to that taken for the tetrahedron. Let the faces be
contained in the planes n
i
· (X − V
i
) = 0, where V
i
is a vertex on the face and n
i
is an outer normal vector to the face. The point P is inside the polyhedron when
n
i
· (P − V
i
)<0 for all i. The point is outside if n
i
· (P − V
i
)>0 for some i.The
point is on the polyhedron boundary itself if n
i
· (P −V
i
) ≤ 0 for all i with equality
occurring for at least one i. If one equality occurs, the point is interior to a face. If two
equalities occur, the point is interior to an edge. If three or more equalities occur, the
point is a vertex. In this latter case, the number of equalities is the number of faces
sharing that vertex.
In any case, if we examine each face i = 0, 1, 2, ..., n − 1 in turn, and find that
all the dot products have a negative value, then P is inside the polyhedron, and
the distance is zero. Otherwise, we find one or more faces whose signed distance
is nonnegative, and we then must compute the distance between P and each such
face, and the distance is the minimum of such distances so calculated. If the faces
are triangular, then the algorithm of Section 10.3.2 can be used; otherwise, the more
general algorithm of Section 10.3.4 must be used.
Point to General Polyhedron
We start by noting that a point that is contained within a polyhedron is considered to
be at zero distance from the polyhedron. Thus, in general we can first test the point for
containment inside the polyhedron using the algorithm described in Section 13.4.3
for general polyhedra. If the point is in the polyhedron, then its distance is zero, and
no further tests need be done. Otherwise, we must then apply a method analogous to
that used in the previous section for convex polyhedra—for each face, if the point P
is on the outside of the face, find the distance from P to that face using the algorithm
of either Section 10.3.2 or Section 10.3.4 if the face is triangular or nontriangular,
respectively.