Skip to content
ExtendedSource checked

Ray-Triangle Intersection

Finds whether and where a ray hits a triangle.

Quick Facts

Compact metadata for implementation and discovery.

Category
Geometry
Difficulty
Intermediate
Family
Geometric Intersection
Tier
Extended
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
5
Code example
Ready
Visualization
Ready
Aliases
Moller-Trumbore Intersection, Möller-Trumbore Intersection

Overview

Ray-Triangle Intersection is a core geometric test for rendering, collision picking, and spatial queries.

Core Concepts

ray equationbarycentric coordinatesplane intersectioninside-triangle test

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(1)

When to Use

  • Use when a ray needs an exact hit test against triangle geometry.
  • Use when ray tracing is a central requirement.

When Not to Use

  • Avoid when a bounding volume can reject the ray before triangle-level tests are needed.
  • Avoid when floating-point precision or degenerate geometry cannot be handled robustly.

What It Does

  • Tests a ray against a triangle plane
  • Checks whether the hit lies inside the triangle
  • Returns hit distance and barycentric coordinates

Use Cases

  • Ray tracing
  • Mouse picking in 3D
  • Collision queries

Inputs

  • Ray origin and direction
  • Triangle vertices

Outputs

  • Hit flag
  • Ray distance
  • Barycentric coordinates

Key Formulas (1)

Ray equation

p(t) = origin + t · direction
p(t) = origin + t * direction

Represents every point along the ray.

Pseudocode

  1. 1.Compute triangle edge vectors
  2. 2.Solve for ray distance and barycentric coordinates
  3. 3.Reject if the ray is parallel or behind the origin
  4. 4.Reject if barycentric coordinates fall outside the triangle
  5. 5.Return the hit

Canonical Example

Input
ray starts in front of a triangle and points toward it
Output
hit = true, t = 4.2
Explanation
The test solves the ray position and verifies it lies inside the triangle.

Implementation Notes

  • Use an epsilon for determinant checks and document backface-culling behavior.
  • Use robust predicates or tolerances when near-degenerate inputs are expected.
  • Keep a tiny example with expected output beside the implementation.

Common Pitfalls

  • Not handling nearly parallel rays can create unstable hits.
  • Collinear, overlapping, and duplicate points need explicit tie-breaking rules.
  • Not defining boundary, empty, or degenerate inputs before implementation.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show a ray piercing a triangle and the hit point expressed with barycentric weights.

Ray-Triangle Intersection mechanism walkthrough step 1 of 5
Step 1 of 5: Compute triangle edge vectors
geometry-diagram

Notes

Moller-Trumbore is a common fast formulation of this test.

Sources (2)

What each reference supports for this entry.

Real-Time Rendering

Book

Rendering reference for ray-geometry intersection tests including ray-triangle intersection.

Open source

Real-Time Collision Detection

Book

Geometric collision reference for Ray-Triangle Intersection's primitive tests, bounding volumes, and numerical edge cases.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Ray-triangle hit points are often represented with barycentric coordinates.

Often paired withBVH Traversal

BVH traversal often ends in ray-triangle intersection tests.

Ray tracers use ray-triangle tests at primitive intersections.

Tags

GeometryRay IntersectionComputational GeometryGraphics