Graphics Reference
In-Depth Information
n
T
T
R
r
Q
-
v
C
C
v
D
P
P
(a)
(b)
Figure 5.36
Illustrating Nettle's method for intersecting a moving sphere against a triangle.
// Subtract movement of s1 from both s0 and s1, making s1 stationary
Vectorv=v0-v1;
// Can now test directed segment s = s0.c + tv, v = (v0-v1)/||v0-v1|| against
// the expanded sphere for intersection
Point q;
float vlen = Length(v);
if (IntersectRaySphere(s0.c, v / vlen, s1, t, q)) {
return t <= vlen;
}
return 0;
}
5.5.6
Intersecting Moving Sphere Against Triangle
(and Polygon)
Let a sphere
S
be specified by a center
C
and a radius
r
, and let
v
be the direction
vector for
S
such that the sphere center movement is given by
C
(
t
)
=
C
+
t
v
over the
interval of motion 0
≤
t
≤
1. Let
T
be a triangle and
n
be the unitized normal to this
triangle.
A simple test, both conceptually and computationally, for intersecting the sphere
against the triangle is suggested in [Nettle00]. Without loss of generality, assume the
sphere is in front of the plane of triangle
T
, moving so as to end up behind the plane.
In this situation, the first point on the sphere to come in contact with the plane is
D
1, against the
plane; let
P
be the intersection point. If
P
lies inside the triangle, then
t
is the desired
time of intersection and
P
the point of contact (Figure 5.36a).
For the case in which
P
lies outside the triangle, let
Q
be the point on the triangle
closest to
P
. If the moving sphere hits the triangle at all, then
Q
is the point it will hit
=
C
−
r
n
. Now intersect the directed segment
D
+
t
v
,0
≤
t
≤