# Triangle Intersection Tests

Aug00: Triangle Intersection Tests

```    bool PointInTriangle (i, p<sub>0</sub>, p<sub>1</sub>, p<sub>2</sub>)
returns ({TRUE, FALSE},u,v);
1: e<sub>0</sub>=i-p<sub>0</sub>
2: e<sub>1</sub>=p<sub>1</sub>-p<sub>0</sub>
3: e<sub>2</sub>=p<sub>2</sub>-p<sub>0</sub>
4: if (e1x=0)
5:   if (e<sub>2x</sub>=0) return (FALSE,0,0);
6:   u=e<sub>0x</sub>/e<sub>2x</sub>
7:   if (u<0 or u>1) return FALSE,0,0);
8:   if (e<sub>1y</sub>=0) return FALSE,0,0)
9:   v=( e<sub>0y</sub>-e2<sub>y</sub>u)/e<sub>1y</sub>
10:   if (v<0) return (FALSE,0,0);
11: else
12:   d = e<sub>2y</sub>e<sub>1x</sub>-e<sub>2x</sub>e<sub>1y</sub>
13:   if (d=0) return (FALSE,0,0);
14:   u = (e<sub>0y</sub>e<sub>1x</sub>-e<sub>0x</sub>e<sub>1y</sub>)/d
15:   if (u<0 or u>1) return (FALSE,0,0);
16:   v = (e<sub>0x</sub>-e<sub>2x</sub>u) / e<sub>1x</sub>
17:   if (v<0) return (FALSE,0,0);
18: if (u+v>1) return (FALSE,0,0);
19: return (TRUE,u,v);

```

### More Insights

 To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.