# Triangle Intersection Tests

#### Source Code Accompanies This Article. Download It Now.

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.

# First C Compiler Now on Github

The earliest known C compiler by the legendary Dennis Ritchie has been published on the repository.

Quick Read

# HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

Quick Read

# Building Bare Metal ARM Systems with GNU

All you need to know to get up and running... and programming on ARM

Quick Read

# Amazon's Vogels Challenges IT: Rethink App Dev

Amazon Web Services CTO says promised land of cloud computing requires a new generation of applications that follow different principles.

Quick Read

# How to Select a PaaS Partner

Eventually, the vast majority of Web applications will run on a platform-as-a-service, or PaaS, vendor's infrastructure. To help sort out the options, we sent out a matrix with more than 70 decision points to a variety of PaaS providers.

Quick Read

More "Best of the Web" >>