CalcWorldHub
Free online calculator · no signup

Forward ray sphere intersections calculator

Find forward intersections of a ray with a sphere and report the associated ray parameters.

4,000 tools
Forward ray sphere intersections calculator — Ray origin x y z, Ray direction x y z, Sphere center x y z and calculation method
Forward ray sphere intersections calculator: inputs and calculation method.

How to use this calculator

Find forward intersections of a ray with a sphere and report the associated ray parameters.

  1. Enter Ray origin x y z, Ray direction x y z, Sphere center x y z, Sphere radius. Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Calculation guide

Forward ray sphere intersections explained

Solve the ray–sphere quadratic and retain only roots at or in front of the ray origin.

Forward intersection count2
Forward intersection count: 2 in the worked scenario.

How the calculation works

Solve |O+tD−C|²=r² for t≥0

Substituting O+tD into the sphere equation gives a quadratic with coefficients D·D, 2D·(O−C), and |O−C|²−r². A cancellation-resistant quadratic solve finds real roots; negative roots are discarded and a tangent is counted once.

Set up the calculation

o — Ray origin x y z
Three coordinates of the ray’s starting point in a common Cartesian frame.
d — Ray direction x y z
Three components of the forward direction vector. It need not be unit length; reported t scales with the vector.
c — Sphere center x y z
Three coordinates of the sphere center in the same frame and length units.
r — Sphere radius
Positive sphere radius in the same length units as origin and center coordinates.

Limits of this model

Direction must be nonzero; a tangent counts once, and negative-t intersections behind the origin are discarded.

Check this example

Ray origin x y z = 0, 0, 3; Ray direction x y z = 0, 0, -1; Sphere center x y z = 0, 0, 0; Sphere radius = 1.

  • Forward intersection count: 2
  • Forward ray parameters: 2, 4

The forward ray parameters are t=2 and t=4, so it enters and exits the sphere. Here the direction is unit length, making t equal to distance units.

Interpreting the result

Nonnegative roots are points on the forward ray; the two roots here mark entry and exit. If the direction vector is not unit length, t is a parameter rather than physical distance.

Frequently asked questions

Can the origin start inside the sphere?

Yes, normally only the forward exit remains.

Are t values distances?

Only for a normalized direction vector.

Does a tangent count twice?

No.

How do I use the Forward ray sphere intersections calculator?

Enter Ray origin x y z, Ray direction x y z, Sphere center x y z, Sphere radius. Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Forward ray sphere intersections?

Ray origin x y z = 0, 0, 3; Ray direction x y z = 0, 0, -1; Sphere center x y z = 0, 0, 0; Sphere radius = 1. Forward intersection count: 2 Forward ray parameters: 2, 4 The forward ray parameters are t=2 and t=4, so it enters and exits the sphere. Here the direction is unit length, making t equal to distance units.