Learning path

Full curriculum

Full curriculum

Unit content

Rays and geometric intersection tests

A ray starts at an origin $\mathbf{o}$ and extends in direction $\mathbf{d}$:

$$\mathbf{r}(t)=\mathbf{o}+t\mathbf{d},\qquad t\ge0.$$

Rendering and geometric queries often ask for the smallest positive $t$ at which the ray intersects an object.

For a sphere, substituting the ray equation into the sphere equation produces a quadratic equation in $t$. Its real roots identify entry and exit points.

For a triangle, an intersection can be described by

$$\mathbf{o}+t\mathbf{d} =\lambda_0\mathbf{p}_0+\lambda_1\mathbf{p}_1+\lambda_2\mathbf{p}_2,$$

with barycentric weights summing to one. A hit lies inside the triangle when the weights satisfy the triangle's inside conditions and $t\ge0$.

Intersection routines must also define tolerances and boundary conventions carefully. Near-parallel rays and floating-point roundoff can otherwise produce missed surfaces or self-intersections.

Ray intersection is the geometric primitive underlying ray tracing, picking and many collision queries.