liveBook · Manning

Ray-triangle intersection

As explained in Geometry for Programmers

Ray-triangle intersection is the geometric computation of determining whether a ray intersects a triangle and, if so, finding the intersection point.

Ray-triangle intersection determines whether a ray hits a triangle and, when it does, finds the intersection point. The computation supports raytracing, where rays select pixel colors, and 3D collision tasks such as testing points against triangle meshes or gluing bodies together. section 3.8.1

Represent a ray point as R = P + td and a triangle-plane point as S = A + ABu + ACv. A hit occurs when these points are equal: P + td = A + ABu + ACv. In 3D, this vector equation becomes three scalar equations for t, u, and v. section 3.8.2

Filter the plane intersection using the triangle’s barycentric-style coordinates:

  • Require t >= 0 so the candidate lies along the ray rather than behind its origin. section 3.8.2
  • Require u >= 0, v >= 0, and u + v <= 1 so the candidate lies inside triangle ABC rather than elsewhere on its plane. section 3.8.2
Figure 3.15 A ray may or may not intersect a triangle in 3D.
03-15

Use the spatial figure to distinguish rays that hit the triangle from rays that miss it. section 3.8.1

Figure 3.17 The triangle in its own basis
03-17

Use the triangle’s own coordinate basis to visualize why the inequalities describe exactly its interior and edges. section 3.8.2

How Geometry for Programmers covers it

How deep it goes
Forms the three-equation parametric system and states ray and triangle constraints, stopping before a solution algorithm.
Examples
Uses raytraced pixels, triangle meshes, and basis-coordinate positions such as a midpoint on the BC edge.
What it assumes
Assumes familiarity with 3D vectors, points, rays, and parametric equations while developing the triangle’s coordinate basis.
What you can do after
Evaluate whether a ray intersects a triangle by solving for t, u, and v and checking their constraints.
How it connects
Connects raytracing, collision detection, triangle meshes, vectors, and linear equations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.