I'm making a program which shows if the inputed coordinates of point is inside, outside or on the line of triangle. Triangle's coordiantes are 100, 0; 100, 100; 0,100; I can't figure out algoritm or some kind of comparasion for that. It would be easy for circle or quadrangle but for triangle it's hard(er?) (for me). It would be nice if someone could help.
coordinates inside/outside triangle
Started by skirmish, Jul 18 2010 12:13 PM
5 replies to this topic
#1
Posted 18 July 2010 - 12:13 PM
|
|
|
#2
Posted 18 July 2010 - 12:42 PM
The interior of the triangle is the set of points that satisfy the following:
1) they are not on a line defined by any pair of the vertices
2) for each line defined by a pair of vertices, they are on the same side of the line as the third vertex.
1) they are not on a line defined by any pair of the vertices
2) for each line defined by a pair of vertices, they are on the same side of the line as the third vertex.
#3
Posted 18 July 2010 - 11:22 PM
I understand the idea, but have difficulties transfering it into code. (writing in Pascal).
#4
Posted 19 July 2010 - 06:00 PM
Well, give it a shot and let me see what you come up with.
Do you know the math of both statements?
Do you know the math of both statements?
#5
Posted 06 September 2010 - 12:58 AM
there is much simplier method:
Cross product - Wikipedia, the free encyclopedia
for example if you have triangle ABC and input point D
you must create 6 vectors:
AB, DA
BC, DB
CA, DC
and check the signs of the cross products counted one by one pairs (as showed above) - z axis only. if all signs are the same it means that the point D is in the triangle. if at least one of them is 0 it means that point D is on the triangle if signs differs it means that the point is outside of triangle. Try to implement this. If you fail, paste your code here I will help you. analogically you can implement checking for other polygons (convex only).
you can use also other method. create 3 different triangles (from edge of the traingle and point) and check if sum of areas is equal to area of the main triangle.
to count an area of the triangle you can use this
Heron's formula - Wikipedia, the free encyclopedia
Cross product - Wikipedia, the free encyclopedia
for example if you have triangle ABC and input point D
you must create 6 vectors:
AB, DA
BC, DB
CA, DC
and check the signs of the cross products counted one by one pairs (as showed above) - z axis only. if all signs are the same it means that the point D is in the triangle. if at least one of them is 0 it means that point D is on the triangle if signs differs it means that the point is outside of triangle. Try to implement this. If you fail, paste your code here I will help you. analogically you can implement checking for other polygons (convex only).
you can use also other method. create 3 different triangles (from edge of the traingle and point) and check if sum of areas is equal to area of the main triangle.
to count an area of the triangle you can use this
Heron's formula - Wikipedia, the free encyclopedia
#6
Posted 12 September 2010 - 12:27 PM
If your triangle is always the same, and it has these simplistic coordinates, there's a really easy method. It requires just about no calculations whatsoever.
Just consider: your triangle is half a square. Forget vectors.
Obviously, your coordinates must be less than or equal to 100 to be inside or on the triangle. If that isn't so, then it's outside.
Now, how much is x+y for a point outsdide the triangle? How about inside? How about on the line 0,100-100,0? Get the drift? Quite simple....
Just consider: your triangle is half a square. Forget vectors.
Obviously, your coordinates must be less than or equal to 100 to be inside or on the triangle. If that isn't so, then it's outside.
Now, how much is x+y for a point outsdide the triangle? How about inside? How about on the line 0,100-100,0? Get the drift? Quite simple....


Sign In
Create Account

Back to top










