encyclopegia.org

Möller–Trumbore intersection algorithm

The Möller–Trumbore ray-triangle intersection algorithm, named after its inventors Tomas Möller and Ben Trumbore, is a fast method for calculating the intersection of a ray and a triangle in three dimensions without needing precomputation of the plane equation of the plane containing the triangle.[src] Among other uses, it can be used in computer graphics to implement ray tracing computations involving triangle meshes.[src]

The Möller–Trumbore ray-triangle intersection algorithm, named after its inventors Tomas Möller and Ben Trumbore, is a fast method for calculating the intersection of a ray and a triangle in three dimensions without needing precomputation of the plane equation of the plane containing the triangle.[src] Among other uses, it can be used in computer graphics to implement ray tracing computations involving triangle meshes.[src] Every point on the ray can be expressed by \vec{r}(t) = O + tD , where the parameter t ranges from negative infinity to infinity.[src] The triangle is defined by three vertices, named v_1 , v_2 , v_3 .[src] The plane that the triangle is on, which is needed to calculate the ray-triangle intersection, is defined by a point on the plane, such as v_1 , and a vector that is orthogonal to every point on that plane, such as the cross product between the vector from v_1 to v_2 and the vector from v_1 to v_3 : \vec{n} \cdot (P_1 - P_2) = 0 , where \vec{n} = (v_2 - v_1) \times (v_3 - v_1) , and P_1 and P_2 are any points on the plane.[src] P = w v_1 + u v_2 + v v_3 The coefficients must be non-negative and sum to 1, so w can be replaced with 1 - u - v : \begin{align} P &= (1 - u - v) v_1 + u v_2 + v v_3 \\ P &= v_1 + u (v_2 - v_1) + v (v_3 - v_1) \end{align} where P is any point on the plane.[src] Observe that \vec{e_1} = v_2 - v_1 and \vec{e_2} = v_3 - v_1 are vectors on the edge of the triangle, and together, they span a plane (which goes through the origin).[src] Each point on that plane can be written as u e_1 + v e_2 and can be translated by v_1 to "move" that point onto the plane that the triangle is on.[src] To find u and v for a particular intersection, set the ray expression equal to the plane expression, and put the variables on one side and the constants on the other.[src] \begin{align} O + tD &= v_1 + u(v_2 - v_1) + v(v_3 - v_1) \\ O - v_1 &= -tD + u(v_2 - v_1) + v(v_3 - v_1) \end{align} This is a system of linear equations with three equations (one each for x , y , z ) and three unknowns ( t , u , and v ), and can be represented as a matrix-vector multiplication.[src] \begin{bmatrix} \vert & \vert & \vert \\ -D & (v2 - v1) & (v3 - v1) \\ \vert & \vert & \vert \end{bmatrix} \begin{bmatrix} t \\ u \\ v \end{bmatrix} = O - v_1 This equation will always have a solution when the matrix has three linearly independent column vectors in \mathbb{R}^3 and is thus invertible.[src] This happens if and only if the triangle vertices aren't collinear and the ray isn't parallel to the plane.[src] The algorithm can use Cramer's Rule to find the t , u , and v values for an intersection, and if it lies within the triangle, the exact coordinates of the intersection can be found by plugging in t to the ray's equation.[src] ==Implementations== ===C++ implementation=== The following is an implementation of the algorithm in C++ using the glm library: std::optional ray_intersects_triangle( const vec3 &ray_origin, const vec3 &ray_vector, const triangle3& triangle) { constexpr float epsilon = std::numeric_limits ::epsilon(); vec3 edge1 = triangle.b - triangle.a; vec3 edge2 = triangle.c - triangle.a; // Backface culling, assuming CCW-wound triangles.[src] const vec3 normal = cross(edge1, edge2); // No need to normalize if (dot(normal, ray_vector) > 0) return {}; vec3 ray_cross_e2 = cross(ray_vector, edge2); float det = dot(edge1, ray_cross_e2); if (abs(det) epsilon) return {}; // Ray passes outside edge2's bounds vec3 s_cross_e1 = cross(s, edge1); float v = inv_det * dot(ray_vector, s_cross_e1); if (v epsilon) return {}; // Ray passes outside edge1's bounds // The ray line intersects with the triangle.[src] // We compute t to find where on the ray the intersection is.[src] float t = inv_det * dot(edge2, s_cross_e1); if (t > epsilon) // Ray intersection { return vec3(ray_origin + ray_vector * t); } else // This means that there is a line intersection but not a ray intersection.[src] return {}; } ===Rust implementation=== The following is an implementation of the algorithm in Rust using the glam crate: fn moller_trumbore_intersection (origin: Vec3, direction: Vec3, triangle: Triangle) -> Option { let e1 = triangle.b - triangle.a; let e2 = triangle.c - triangle.a; let ray_cross_e2 = direction.cross(e2); let det = e1.dot(ray_cross_e2); if det > -f32::EPSILON && det 1.0 { return None; } let s_cross_e1 = s.cross(e1); let v = inv_det * direction.dot(s_cross_e1); if v 1.0 { return None; } // At this stage we can compute t to find out where the intersection point is on the line.[src] let t = inv_det * e2.dot(s_cross_e1); if t > f32::EPSILON { // ray intersection let intersection_point = origin + direction * t; return Some(intersection_point); } else { // This means that there is a line intersection but not a ray intersection.[src] return None; } } ===Java implementation=== The following is an implementation of the algorithm in Java using javax.vecmath from Java 3D API: public class MollerTrumbore { private static final double EPSILON = 0.0000001; public static boolean rayIntersectsTriangle(Point3d rayOrigin, Vector3d rayVector, Triangle inTriangle, Point3d outIntersectionPoint) { Point3d vertex0 = inTriangle.getVertex0(); Point3d vertex1 = inTriangle.getVertex1(); Point3d vertex2 = inTriangle.getVertex2(); Vector3d edge1 = new Vector3d(); Vector3d edge2 = new Vector3d(); Vector3d h = new Vector3d(); Vector3d s = new Vector3d(); Vector3d q = new Vector3d(); double a, f, u, v; edge1.sub(vertex1, vertex0); edge2.sub(vertex2, vertex0); h.cross(rayVector, edge2); a = edge1.dot(h); if (a > -EPSILON && a 1.0) { return false; } q.cross(s, edge1); v = f * rayVector.dot(q); if (v 1.0) { return false; } // At this stage we can compute t to find out where the intersection point is on the line.[src] double t = f * edge2.dot(q); if (t > EPSILON) // ray intersection { outIntersectionPoint.set(0.0, 0.0, 0.0); outIntersectionPoint.scaleAdd(t, rayVector, rayOrigin); return true; } else // This means that there is a line intersection but not a ray intersection.[src] { return false; } } }[src]

24 sentences · 24 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Möller–Trumbore intersection algorithm." encyclopegia.org, 2026, https://encyclopegia.org/wiki/m-ller-trumbore-intersection-algorithm. Accessed 27 November 2026.

Chicago

"Möller–Trumbore intersection algorithm." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/m-ller-trumbore-intersection-algorithm.

APA

encyclopegia.org. (2026). Möller–Trumbore intersection algorithm. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/m-ller-trumbore-intersection-algorithm

Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

intersection

stub · references available

Intersection

stub · references available

Leonard Intersection

stub · references available

minimum orbit intersection distance

stub · references available

line–sphere intersection

stub · references available

Intersection

stub · references available

Si Kak Phraya Si intersection

stub · references available

Indochina intersection

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1362828277 · 0.5 · snapshot enwiki-001362828277

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.