» Search

» Toolbox

# Ray Triangle Intersection

To perform a ray-triangle intersection test we need:

• A ray with a known point of origin $\mathbf{o}$, and direction vector $\mathbf{d}$.
• A triangle with three known vertex positions $\mathbf{p_0}$, $\mathbf{v_1}$ and $\mathbf{v_2}$.

## Ray/triangle intersection using barycentric coordinates

There are several ways of computing ray-triangle intersections. The one described here uses barycentric coordinates to parameterise the triangle using two variables u and v. The point $\mathbf{p}$ represented by the u and v is defined:

$\mathbf{p}(u,v) = (1 - u - v)\mathbf{v_0} + u\mathbf{v_1} + v\mathbf{v_2}, \; \; u \geq 0, v \geq 0, u+v \leq 1$

As the parametric ray equation is

$\mathbf{p}(t) = \mathbf{o} + t\mathbf{d}, \; \; t \geq 0$

we can derive a ray/triangle intersection by inserting this into the parametric triangle equation:

$\mathbf{o} + t\mathbf{d} = (1 - u - v)\mathbf{v_0} + u\mathbf{v_1} + v\mathbf{v_2}$

or as described by Möller and Trumbore (1997):

$\begin{bmatrix}-\mathbf{d}, & \mathbf{v_1} - \mathbf{v_0}, & \mathbf{v_2} - \mathbf{v_0}\end{bmatrix} \begin{bmatrix}t \\ u \\ v\end{bmatrix} = \mathbf{o} - \mathbf{v_0}$

...

#### The Society

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide