# Point in triangle testing

1. Jul 8, 2006

### eXt

Hi, how do I test if a point is inside a triangle? The point is assumed to be in the triangle's plane.

2. Jul 8, 2006

### HallsofIvy

Staff Emeritus
How are you given the triangle? If you are given the lines that form the sides of the triangle and the vertices, determine if the point lies on the same side of the line as the opposite vertex.

For example, it the three sides of the triangle lie on x+ y= 4, x= 0, and y= 0. Then the three vertices (solving each pair of equations) are (0,0), (4,0) and (0,4). Is (3,2) inside the triangle? If we substitute the point (0,0) into x+ y= 4 we get 0+ 0= 0< 4 but if we substitute (3,2) we get 3+ 2= 5> 4. No, (3,2) is not on the same side of x+y= 4 as (0,0) and so cannot be inside the triangle.

Is (1,1) inside that triangle? 1+ 1= 2< 4 so (1,1) is on the same side of x+y= 4 as (0,0). The vertex "opposite" y= 0 is (0,4) which has y= 4> 0.
(1,1) has y= 1> 0 so (1,1) is on the same side of y=0 as (0,4). The vertex "opposite" x= 0 is (4, 0) which has x= 4> 0. (1,1) has x= 1> 0 so (1,1) is on the same side of x=0 as (4,0). Since (1,1) is on the same side of each line as the opposite vertex. Yes, (1,1) is inside the triangle.

This isn't really linear or abstract algebra so I am moving it to General Math.

Last edited: Jul 8, 2006
3. Jul 8, 2006

### learningphysics

I think it could be mentioned as a linear algebra question. If the coordinates of 3 points are given... then you can give the coordinates of an arbitrary point in the plane using one of these points and a linear combination of the 2 vectors from this point to the other 2 points. Use this to determine whether the point is inside the triangle. What linear combinations occur for points inside the triangle?

4. Jul 8, 2006

### eXt

What I'm trying to accomplish is to find if a point is within a geometric room consisting of several triangles. I am going to use Jordans curve theorem to find if it is so what I do is the following:
1) Cast a ray from the point (in an arbitrary direction) agains each plane the triangles are in.
2) If the ray intersects with the plane I calculate the point in the plane.
3) Now I need to figure out if this point is within the triangle or just in the plane.
4) And last, count each time the ray intersects with a triangle.

So, what I know about each triangle is it's 3 coordinates.

I've read about the following method but I'm not sure if its good or not:
Calculate a vector from the point to each corner of the triangle, if the sum of the angles between this vectors equals 360 degrees the point is inside.

5. Jul 8, 2006

### learningphysics

What do you think of the method I posted?

6. Jul 9, 2006

### eXt

I'm not exactly sure I understand it, could you draw a nice little image to visualize it?

7. Jul 9, 2006

8. Jul 9, 2006

### eXt

The sum of a and b shoud not exceed 1?

9. Jul 10, 2006

### 0rthodontist

Yes, and also they must both be greater than 0.

Similar Discussions: Point in triangle testing
{"extraction_info": {"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8636031746864319, "perplexity": 577.6948245969876}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-17/segments/1492917118740.31/warc/CC-MAIN-20170423031158-00605-ip-10-145-167-34.ec2.internal.warc.gz"}