Triangle to sphere
To test if a sphere and a triangle intersect, we must first find the point on the triangle that is closest to the center of the sphere. If the distance between the center of the sphere and the closest point is less than the radius of the sphere, we have an intersection:
Getting ready
We are about to implement a function that tests if a triangle and sphere intersect. This function will return a Boolean result. We avoid the expensive square root operation involved in finding distance by checking squared distance against squared radius.
How to do it…
Follow these steps to implement a test for checking if a triangle and sphere intersect:
- Declare the
TriangleSphere
function inGeometry3D.h
:bool TriangleSphere(const Triangle& t, const Sphere& s);
- Declare the
SphereTriangle
convenience macro inGeometry3D.h
:#define SphereTriangle(s, t) \ TriangleSphere(t, s)
- Implement the
TriangleSphere
function inGeometry3D.cpp
:bool TriangleSphere(const Triangle& t, const Sphere...