Graphics Reference
In-Depth Information
a
T
d
h
n
r
P
Q
Figure 5.17 Illustrating the variables involved in the intersection test of a cone against a
plane or halfspace.
The vector m is given by m
=
( n
×
v )
×
v .
If n
×
v is zero, the cone axis is parallel to the plane normal, in which case,
Q
h v is the correct point to test against the halfspace. However, in this case
m is also zero and thus it is not necessary to handle this case specially.
Often cones are specified by giving the halfangle
=
T
+
α
at the cone apex, rather than
the bottom radius r . In that tan
α =
r / h , in these cases r is obtained as r
=
h tan
α
.
Giving r rather than
is clearly a better representation for this test.
If the intersection test is against the plane itself and not a halfspace, the computa-
tion of Q must be changed to lie farthest in the direction of n in the case T lies behind
the plane. The test for intersection now becomes testing that T and Q lie on different
sides of the plane, indicated by ( n
α
·
T )
d and ( n
·
Q )
d having different signs. Of
these, ( n
·
T )
d has already been computed to determine which side of the plane
T lies on.
5.2.5 Testing Sphere Against AABB
Testing whether a sphere intersects an axis-aligned bounding box is best done by com-
puting the distance between the sphere center and the AABB (see Section 5.1.3.1) and
comparing this distance with the sphere radius. If the distance is less than the radius,
the sphere and AABB must be intersecting. To avoid expensive square root operations,
both distance and radius can be squared before the comparison is made without
changing the result of the test. Using the function SqDistPointAABB() defined in
Section 5.1.3.1, the implementation becomes:
// Returns true if sphere s intersects AABB b, false otherwise
int TestSphereAABB(Sphere s, AABB b)
{
// Compute squared distance between sphere center and AABB
 
Search WWH ::




Custom Search