# Fast 2D Line Triangle Intersection test

In a 2D plane, I have a line segment ($P_0$ and $P_1$) and a triangle, defined by three points ($t_0$, $t_1$ and $t_2$).

My goal is to test, as efficiently as possible ( in terms of computational time), whether the line touches, or cuts through, or overlaps with one of the edge of the triangle.

What is the algorithm I can use for this?

-
 You might be able to adapt this... – J. M. Dec 14 '11 at 7:10 @J.M., I think not. The ray-triangle intersection is in 3D, as such, we can talk about a ray passing through the triangle at a point. But this is not the situation in 2D. In 2D, the normal of the triangle and the 2D line is 90 degree apart. – Graviton Dec 14 '11 at 7:24

Let $(x, y)$ be one of the four direction vectors mentioned above. Then $n := (y, -x)$ is a vector that is orthogonal to it. Calculate the dot product of $n$ with $t_0$, $t_1$ and $t_2$, which gives you three scalars. Set $t_{min}$ and $t_{max}$ to the minimum/maximum of these three. Do the same for $P_0$ and $P_1$, which gives you $p_{min}$ and $p_{max}$.