i
i
i
i
i
i
i
i
760 16. Intersection Test Methods
The entire test starts with six determinant tests, and the first three share
the first arguments, so there is a lot to gain in terms of shared computations.
In principle, the determinant can be computed using many smaller 2 × 2
subdeterminants (see Section A.3.1),andwhentheseoccurinmorethan
one 4 ×4 determinant, the computations can be shared. There is code on
the web for this test [467], and it is also possible to augment the code to
compute the actual line segment of intersection.
If the triangles are coplanar, they are projected onto the axis-aligned
plane where the areas of the triangles are maximized (see Section 16.9).
Then, a simple two-dimensional triangle-triangle overlap test is performed.
First, test all closed edges (i.e., including endpoints) of T
1
for intersection
with the closed edges of T
2
. If any intersection is found, the triangles
intersect. Otherwise, we must test whether T
1
is totally contained in T
2
or vice versa. This can be done by performing a point-in-triangle test (see
Section 16.8) for one vertex of T
1
against T
2
,andviceversa.
Robustness problems may arise when the triangles are nearly coplanar
or when an edge is nearly coplanar to the other triangle (especially when
the edge is close to an edge of the other triangle). To handle these cases in
a reasonable way, a user-defined constant, EPSILON (), can be used.
12
For
example, if |[p
2
, q
2
, r
2
, p
1
]| <,thenwemovep
1
so that [p
2
, q
2
, r
2
, p
1
]=
0. Geometrically, this means that if a point is “close enough” to the other
triangle’s plane, it is considered to be on the plane. The same is done for
the points of the other triangle, as well. The source code does not handle
degenerate triangles (i.e., lines and points). To do so, those cases should
be detected first and then handled as special cases.
16.12 Triangle/Box Overlap
This section presents an algorithm for determining whether a triangle in-
tersects an axis-aligned box. Such a test can be used to build voxel-spaces,
test triangles against boxes in collision detection, and test polygons against
canonical view volumes (see Section 4.6), and thus potentially eliminate the
need for calls to clipping and lighting routines, etc.
Green and Hatch [441] present an algorithm that can determine whether
an arbitrary polygon overlaps a box. Akenine-M¨oller [11] developed a faster
method that is based on the separating axis test (page 731), and which we
present here.
We focus on testing an axis-aligned bounding box (AABB), defined by
a center c, and a vector of half lengths, h, against a triangle Δu
0
u
1
u
2
.
To simplify the tests, we first move the box and the triangle so that the
box is centered around the origin, i.e., v
i
= u
i
− c, i ∈{0, 1, 2}.This
12
For floating point precision, =10
−6
works for “normal” data.