Ray-Sphere Intersection
August 6th, 2009
No comments
A ray, , where
is the origin of the ray,
is the direction of the ray, and
is the distance along the ray:
Equation of a sphere:
A point on the surface of the sphere, , and the center of the sphere,
:
Plug in the ray and solve for :
We now have a quadratic equation of the form , where:
This can be plugged into the quadratic formula:
- If the determinant,
, is negative, there exist no real roots and therefore there is no intersection.
- If the determinant is 0, there is exactly one intersection; the ray is tangent to the sphere at this single point.
- If the determinant is positive, there are two intersections. The ray penetrates the sphere: one point in, one point out.
- If
, the intersection is 'behind' the ray starting point.