How this calculation works
A parametric line describes points by an origin and a nonzero direction vector. Intersecting it with a sphere produces a quadratic relation in the parameter. This page evaluates scaled line geometry, computes the candidate parameters and filters them according to line, ray or segment mode. Returned rows include the intersection coordinates and a numerical residual measuring how closely each point lies on the sphere surface.
P(t)=O+tD; solve |O+tD−C|²=r², then retain roots in the selected parameter domain.A worked example
For origin (−2,0,0), direction (1,0,0), sphere center (0,0,0) and radius one, the line reaches the sphere at t=1 and t=3. The points are (−1,0,0) and (1,0,0). Ray mode keeps both because both parameters are nonnegative. Segment mode retains only t=1 because that segment ends at origin plus direction=(−1,0,0); it does not extend to the farther line intersection.
Good to know
Direction must be nonzero, and its scale is preserved rather than silently normalized in the parameter definition. Coordinates and direction components are within ±10⁹. The solver is numerical and uses a relative tolerance near tangency; extremely close roots can merge into a tangent classification. Domain filtering uses the computed parameter values. This page does not calculate the length or volume of a thick beam inside a sphere.
Reference: Physically Based Rendering — spheres and stable intersection calculations (opens in a new tab) ↗
Parameter values and travel distances are not automatically the same
The distance traveled from the origin to P(t) along the line is |t| times the direction-vector length. Only a unit direction makes parameter magnitude equal geometric distance. Replacing D by twice D describes the same infinite line but halves every root parameter. In segment mode, however, it changes the endpoint as well, so it describes a different finite geometric object.
A segment uses O at t=0 and O+D at t=1. If you have two endpoint coordinates A and B, enter origin A and displacement B−A. Entering B itself as the direction is a common transcription error. The line equations may still produce plausible numbers, but they would refer to the wrong segment. The explicit domain note and the coordinate table make that convention checkable.
The Point to triangle distance calculator in 3D minimizes distance to a bounded triangular surface. This line–sphere page instead solves intersection equations and filters their parameters.
A line hit can fall outside the ray or segment you selected
A ray starting beyond the sphere and pointing farther away can have two negative line roots but no permitted ray intersection. Those roots must be discarded, not moved to t=0. Similarly, a segment can lie completely inside the sphere while neither endpoint-to-endpoint parameter range meets the sphere surface. That case has no surface intersection in the selected domain even though the segment is contained in the solid ball.
Tangency corresponds to the line’s perpendicular distance equaling the radius. Near that boundary, floating roundoff limits a strict secant-versus-tangent decision. The page labels its tolerance and returns surface residuals rather than implying an exact geometric proof. Measurements close to tangency may also be uncertain before any arithmetic is performed. Keep those modeling and numerical uncertainties separate when using a result for a physical clearance decision.
A few questions, answered
Why can the solver return one point for a segment?
Only one of the two infinite-line roots may lie in 0≤t≤1, or the line may be tangent within numerical tolerance.
Does no ray intersection mean the infinite line misses?
No. The infinite line may intersect only behind the ray origin. The selected parameter domain determines which roots are relevant.