488 Chapter 11 Intersection in 3D
intersection = line.origin+t*line.direction;
return true;
}
Ray-Triangle Intersection
A ray is only defined for t ≥ 0, so we can simply check if the t valuecomputedis
nonnegative, and accept or reject the intersection.
Line Segment–Triangle Intersection
We assume a line segment is represented by a pair of points {P
0
, P
1
}. We can again em-
ploy a similar algorithm for line-triangle intersection by converting the line segment
into line form. The segment is defined for 0 ≤t ≤ 1, and so we can simply compare
the t-value to that range, and accept or reject the intersection.
11.1.3 Linear Components and Polygons
Computation of intersections between linear components and triangles was aided
by our ability to specify the point of intersection in barycentric coordinates; the
intersection was guaranteed (within floating-point error) to be in the plane of the
triangle. Unfortunately, this trick cannot be directly exploited for polygons in general.
For polygons that are not self-intersecting, it is theoretically possible to triangulate
them, and then apply the linear component–triangle intersection algorithm on each
triangle, but this is likely not efficient.
In the following sections, the polygons are assumed to be planar within floating-
point error, non-self-intersecting, closed, and consisting of a single contour. Polygons
are represented by a list of n vertices: {V
0
, V
1
, ..., V
n−1
}. The plane of the polygon is
implied by the vertices and represented in the usual fashion as a normal and distance
from the origin: ax +by + cz + d = 0, where a
2
+ b
2
+ c
2
= 1.
Because we cannot (in general) exploit the “barycentric coordinates trick” we
used for triangles, linear component–polygon intersection requires several steps:
1. Compute the plane equation for the polygon. This can be done by selecting an
arbitrary vertex as a point on the plane and then computing the normal using
the cross product of the vectors formed by that vertex and its neighbors; however,
in general polygons are not exactly planar, so a more robust mechanism, such
as Newell’s method (Tampieri 1992) or the hyperplanar fitting of Section A.7.4
should be employed.
2. Compute the intersection of the linear component with the plane (see Sec-
tion 11.1.1).