i
i
i
i
i
i
i
i
16.18. Dynamic Intersection Testing 789
whichneedstobeintherange[0, 1]. If d is not in this range, the edge is
considered missed.
19
Using this d in Equation 16.70 gives the point where
the sphere first intersects the edge. Note that if the point of first intersec-
tion is needed, then all three edges must be tested against the sphere, as
the sphere could hit more than one edge.
The sphere/edge test is computationally complex. One optimization for
this test is to put an AABB around the sphere’s path for the frame and
test the edge as a ray against this box before doing this full test. If the
line segment does not overlap the AABB, then the edge cannot intersect
the sphere [1137].
If no edge is the first point of intersection for the sphere, further testing
is needed. Recall that the sphere is being tested against the first point of
contact with the polygon. A sphere may eventually hit the interior or an
edge of a polygon, but the tests given here check only for first intersection.
The third possibility is that the first point of contact is a polygon vertex.
So, each vertex in turn is tested against the sphere. Using the concept of
relative motion, testing a moving sphere against a static point is exactly
equivalent to testing a sphere against a moving point, i.e., a ray. Using the
ray/sphere intersection routine in Section 16.6 is then all that is needed.
To test the ray c
t
= c + tv against a sphere centered at p
0
with radius,
r, results can be reused from the previous edge computations to solve t,as
follows:
a = k
ss
,
b = −2k
gs
,
c = k
gg
− r
2
.
(16.75)
Using this form avoids having to normalize the ray direction for
ray/sphere intersection. As before, solve the quadratic equation shown
in Equation 16.64 and use the lowest valid root to compute when in the
frame the sphere first intersects the vertex. The point of intersection is the
vertex itself, of course.
In truth, this sphere/polygon test is equivalent to testing a ray (rep-
resented by the center of the sphere moving along a line) against the
Minkowski sum of the sphere and polygon. This summed surface is one
in which the vertices have been turned into spheres of radius r,theedges
into cylinders of radius r, and the polygon itself raised and lowered by r
to seal off the object. See Figure 16.31 for a visualization of this. This is
the same sort of expansion as done for frustum/sphere intersection (Sec-
tion 16.14.2). So the algorithm presented can be thought of as testing a
19
In fact, the edge could be hit by the sphere, but the hit point computed here would
not be where contact is actually made. The sphere will first hit one of the vertex
endpoints, and this test follows next.