Graphics Reference
In-Depth Information
n
n
n
P
P
P
(a)
(b)
(c)
Figure 5.15 Illustrating the three sphere-plane tests. (a) Spheres intersecting the plane. (b)
Spheres fully behind the plane. (c) Spheres intersecting the negative halfspace of the plane.
Spheres testing true are shown in gray.
The IsZeroVector() function tests if its argument is a vector with a magnitude
sufficiently close to zero (according to some tolerance value; see Section 11.3.1).
Widening the tolerance intervals and treating near-parallel edges as parallel may
result in near-intersections being interpreted as intersections. Overall, this is much
more attractive than the alternative: two intersecting objects falsely reported as
nonintersecting due to the projection onto a zero-vector separating axis, for example.
A related source of robustness errors is when the vectors used in the cross product
have a large magnitude, which may result in additional loss of precision in the calcu-
lations involving the cross product. If a bound on the magnitude of the input vectors
it not known, it is prudent to normalize them before computing the cross product to
maintain precision.
5.2.2 Testing Sphere Against Plane
It is possible to test a sphere against a plane in several ways. This section describes
three such tests: testing if the sphere intersects the plane, if the sphere lies fully behind
the plane, and if the sphere intersects the negative halfspace of the plane. Figure 5.15
illustrates these three scenarios.
Let a sphere S be specified by a center position C and a radius r , and let a plane
π
be
specified by ( n
1. To determine if the
sphere is intersected by the plane, the plane equation can be evaluated for the sphere
center. Because n is unit, the resulting value corresponds to the signed distance of
the sphere center from the plane. If the absolute value of the distance is within the
sphere radius, the plane intersects the sphere:
·
X )
=
d , where n is a unit vector; that is,
n
=
// Determine whether plane p intersects sphere s
int TestSpherePlane(Sphere s, Plane p)
{
// For a normalized plane (|p.n| = 1), evaluating the plane equation
 
Search WWH ::




Custom Search