PDA

View Full Version : Point in triangle testing


eXt
Jul8-06, 12:30 PM
Hi, how do I test if a point is inside a triangle? The point is assumed to be in the triangle's plane.

HallsofIvy
Jul8-06, 04:57 PM
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.

learningphysics
Jul8-06, 05:18 PM
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?

eXt
Jul8-06, 05:46 PM
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.

learningphysics
Jul8-06, 06:06 PM
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.

What do you think of the method I posted?

eXt
Jul9-06, 04:19 AM
I'm not exactly sure I understand it, could you draw a nice little image to visualize it?

0rthodontist
Jul9-06, 09:41 AM
http://img209.imageshack.us/my.php?image=triangle9da.png
What can you say about a and b since P is in ABC?

eXt
Jul9-06, 09:49 AM
The sum of a and b shoud not exceed 1?

0rthodontist
Jul10-06, 01:16 PM
Yes, and also they must both be greater than 0.