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. Among other uses, it can be used in computer graphics to implement ray tracing computations involving triangle meshes.
Calculation
Definitions The ray is defined by an origin point O {\displaystyle O} and a direction vector D {\displaystyle D} . Every point on the ray can be expressed by r → ( t ) = O + t D {\displaystyle {\vec {r}}(t)=O+tD} , where the parameter t {\displaystyle t} ranges from negative infinity to infinity. The triangle is defined by three vertices, named v 1 {\displaystyle v_{1}} , v 2 {\displaystyle v_{2}} , v 3 {\displaystyle v_{3}} . 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 {\displaystyle 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 {\displaystyle v_{1}} to v 2 {\displaystyle v_{2}} and the vector from v 1 {\displaystyle v_{1}} to v 3 {\displaystyle v_{3}} :
n → ⋅ ( P 1 − P 2 ) = 0 {\displaystyle {\vec {n}}\cdot (P_{1}-P_{2})=0} , where n → = ( v 2 − v 1 ) × ( v 3 − v 1 ) {\displaystyle {\vec {n}}=(v_{2}-v_{1})\times (v_{3}-v_{1})} , and P 1 {\displaystyle P_{1}} and P 2 {\displaystyle P_{2}} are any points on the plane.
Check if the ray is parallel to the triangle First, find out if the line produced by the ray intersects with the plane that the triangle is on, and if it does, find the coordinates of that intersection. The only way that the line will not intersect the plane is if the ray's direction vector is parallel to the plane. When this happens, the dot product between the ray's direction vector and the plane's normal vector will be zero. Otherwise, the line does intersect the plane somewhere, but not necessarily within the triangle.
Check if the ray-plane intersection lies outside the triangle Using barycentric coordinates, any point on the triangle can be expressed as a convex combination of the triangle's vertices:
P = w v 1 + u v 2 + v v 3 {\displaystyle P=wv_{1}+uv_{2}+vv_{3}}
The coefficients must be non-negative and sum to 1, so w {\displaystyle w} can be replaced with 1 − u − v {\displaystyle 1-u-v} :
… excerpt ends here. Continue reading the full article.
