Graphics Reference
In-Depth Information
Figure 5.18 A sphere that does not lie fully outside any face plane of an AABB but never-
theless does not intersect the AABB.
{
// Find point p on OBB closest to sphere center
ClosestPtPointOBB(s.c, b, p);
// Sphere and OBB intersect if the (squared) distance from sphere
// center to point p is less than the (squared) sphere radius
Vectorv=p-s.c;
return Dot(v, v) <= s.r * s.r;
}
5.2.7 Testing Sphere Against Triangle
The test for intersection between a sphere and a triangle follows the same pattern as
testing a sphere against a box. First, the point P on the triangle closest to the sphere
center is computed. The distance between P and the sphere center is then compared
against the sphere radius to detect possible intersection:
// Returns true if sphere s intersects triangle ABC, false otherwise.
// The point p on abc closest to the sphere center is also returned
int TestSphereTriangle(Sphere s, Point a, Point b, Point c, Point &p)
{
// Find point P on triangle ABC closest to sphere center
p = ClosestPtPointTriangle(s.c, a, b, c);
 
Search WWH ::




Custom Search