Skip to content
Part IA Michaelmas Term

Ray-Object Intersections

Intersection Testing

Finding where a ray hits geometric objects is fundamental to ray tracing.

Ray-Sphere Intersection

Given:

  • Ray: P(s)=O+sD\mathbf{P}(s) = \mathbf{O} + s\mathbf{D}
  • Sphere: (PC)(PC)=r2(\mathbf{P} - \mathbf{C}) \cdot (\mathbf{P} - \mathbf{C}) = r^2

Substituting the ray equation: (O+sDC)(O+sDC)=r2(\mathbf{O} + s\mathbf{D} - \mathbf{C}) \cdot (\mathbf{O} + s\mathbf{D} - \mathbf{C}) = r^2

This is a quadratic in ss: as2+bs+c=0as^2 + bs + c = 0

where:

  • a=DDa = \mathbf{D} \cdot \mathbf{D}
  • b=2D(OC)b = 2\mathbf{D} \cdot (\mathbf{O} - \mathbf{C})
  • c=(OC)(OC)r2c = (\mathbf{O} - \mathbf{C}) \cdot (\mathbf{O} - \mathbf{C}) - r^2

Discriminant

The discriminant d=b24acd = b^2 - 4ac determines intersection type:

  • d<0d < 0: No intersection (miss)
  • d=0d = 0: Tangent (one intersection)
  • d>0d > 0: Two intersections (enter and exit)

Solutions

s1=b+d2a,s2=bd2as_1 = \frac{-b + \sqrt{d}}{2a}, \quad s_2 = \frac{-b - \sqrt{d}}{2a}

The closest valid intersection is the smallest positive ss.

Ray-sphere intersection showing both hit points

Ray-Plane Intersection

Given:

  • Ray: P(s)=O+sD\mathbf{P}(s) = \mathbf{O} + s\mathbf{D}
  • Plane: PN+d=0\mathbf{P} \cdot \mathbf{N} + d = 0

where N\mathbf{N} is the plane normal and dd is the distance offset.

Substituting: s=dNONDs = \frac{-d - \mathbf{N} \cdot \mathbf{O}}{\mathbf{N} \cdot \mathbf{D}}

Valid if:

  • s0s \geq 0 (intersection in front of origin)
  • ND0\mathbf{N} \cdot \mathbf{D} \neq 0 (ray not parallel to plane)

Ray-Polygon Intersection

For a polygon:

  1. Intersect the ray with the plane containing the polygon
  2. Check if the intersection point lies inside the polygon (2D geometry test)

For a disc: Check if distance from centre is less than radius.

Ray-Cone Intersection (2022 Paper 3 Question 3)

For a cone with apex at origin, base radius rr, height hh, axis along yy:

Implicit equation: x2+z2(rh)2y2=0x^2 + z^2 - \left(\frac{r}{h}\right)^2 y^2 = 0

Intersection Method

  1. Base: Intersect ray with plane y=hy = h; accept if x2+z2r2x^2 + z^2 \leq r^2
  2. Side: Substitute ray into implicit equation, solve quadratic in ss

Normal Calculation

For a point (x,y,z)(x, y, z) on the cone side, the normal is proportional to: N(2x,2(rh)2y,2z)\mathbf{N} \propto \left(2x, -2\left(\frac{r}{h}\right)^2 y, 2z\right)

The normal is the gradient of the implicit function f(x,y,z)=0f(x, y, z) = 0.

Transformed Objects

For an object transformed by matrix M\mathbf{M}:

  1. Transform the ray by M1\mathbf{M}^{-1}
  2. Intersect with the canonical (untransformed) object
  3. Transform the intersection point back by M\mathbf{M}
  4. Transform the normal by (M1)(\mathbf{M}^{-1})^\top

Summary

  • Ray-sphere intersection reduces to a quadratic equation
  • Ray-plane intersection is a simple division
  • Polygon intersections require inside/outside tests
  • Cone normals are computed from the implicit gradient
  • Transformed objects require transforming the ray by the inverse matrix

Past Paper Questions

2022 Paper 3 Question 3: Derive the ray-cone intersection. Find the normal at an intersection point.