i
i
i
i
i
i
i
i
16.9. Ray/Polygon Intersection 751
n −1 and the polygon is closed by the edge from v
n−1
to v
0
. The plane of
the polygon
9
is denoted π
p
: n
p
· x + d
p
=0.
We first compute the intersection between the ray (Equation 16.1) and
π
p
, which is easily done by replacing x by the ray. The solution is presented
below:
n
p
·(o + td)+d
p
=0
⇐⇒
t =
−d
p
− n
p
· o
n
p
·d
.
(16.26)
If the denominator |n
p
·d| <,where is a very small number,
10
then
the ray is considered parallel to the polygon plane and no intersection oc-
curs.
11
Otherwise, the intersection point, p, of the ray and the polygon
plane is computed: p = o + td,wherethet-value is that from Equa-
tion 16.26. Thereafter, the problem of deciding whether p is inside the
polygon is reduced from three to two dimensions. This is done by project-
ing all vertices and p to one of the xy-, xz-, or yz-planes where the area of
the projected polygon is maximized. In other words, the coordinate com-
ponent that corresponds to max(|n
p,x
|, |n
p,y
|, |n
p,z
|) can be skipped and
the others kept as two-dimensional coordinates. For example, given a nor-
mal (0.6, −0.692, 0.4), the y component has the largest magnitude, so all
y coordinates are ignored. Note that this component information could
be precomputed once and stored within the polygon for efficiency. The
topology of the polygon and the intersection point is conserved during this
projection (assuming the polygon is indeed flat; see Section 12.2 for more
on this topic). The projection procedure is shown in Figure 16.11.
The question left is whether the two-dimensional ray/plane intersection
point p is contained in the two-dimensional polygon. Here, we will review
just one of the more useful algorithms—the “crossings” test. Haines [482]
and Schneider and Eberly [1131] provide extensive surveys of two-
dimensional, point-in-polygon strategies. A more formal treatment can
be found in the computational geometry literature [82, 975, 1033]. Lagae
and Dutr´e [711] provide a fast method for ray/quadrilateral intersection
basedontheM¨oller and Trumbore ray/triangle test. Walker [1315] pro-
vides a method for rapid testing of polygons with more than 10 vertices.
Nishita et al. [936] discuss point inclusion testing for shapes with curved
edges.
9
This plane can be computed from the vertices on the fly or stored with the polygon,
whichever is most convenient. It is sometimes called the supporting plane of the polygon.
10
An epsilon of 10
−20
or smaller can work, as the goal is to avoid overflowing when
dividing.
11
We ignore the case where the ray is in the polygon’s plane.