Line–sphere intersection
From Wikipedia, the free encyclopedia
In analytic geometry, the
intersection of a line and a sphere can be the empty set, a point, or two points. Distinguishing these cases, and determining equations for the points in the latter cases have use, for example, when calculating ray intersections in ray tracing.
Equation for a sphere
-
- s? - center point and radius
Equation for a line starting at (0,0,0)
- x = d * lx
- y = d * ly
- z = d * lz
- d - distance along line from starting point
- l? - direction of line
Solving for d
- Equations combined
- Expanded
- Factored
- Plugged into quadratic formula and simplified