Ray Sphere Intersection
From CGAFaq
Given a ray R given as:
where
is a direction vector
is a starting point
and a sphere given as:
where
is the origin of the sphere
is the radius of the sphere
The intersection is found by substituting and solving for t:
By bilinearity of the dot product:
This is a quadratic equation in t, which can be solved by using the standard formula.
If the discriminant of this equation is less than 0, the line does not intersect the sphere. If it is zero, the line is tangential to the sphere and if it is greater than zero it intersects at two points. Solving the equation and substituting the values of t into the ray equation will give you the points.
[edit]
Reference
- [Glassner:RayTracing]

