Calculating if a Point is Inside/Outside a Triangle in 2D

In summary, the conversation discusses different methods for determining whether a given point lies inside or outside of a triangle in 2D. One method involves using the cross product of normal vectors to determine if the point lies within a triangular prism created by extending the sides of the triangle. Another method involves checking which side of each line formed by the triangle's vertices the point lies on, and if it is on the same side as the third vertex, the point is inside the triangle. An alternative method suggested is to use the area of triangles, where the sum of the areas of three smaller triangles created by the point must equal the area of the original triangle for the point to be inside.
  • #1
debwaldy
38
0
Hi there,so I'm trying to write a vb.net program which will tell me whether a cartesian point in 2D lies inside or outside of a triangle.
I'm not looking for the code or anything, I'm merely wondering how one does this type of calculation manually?
could the cross product be used?if the results of all three cross products point in the same direction the point lies inside the triangle, otherwise it lies outside the triangle?i read this in a forum but i don't honestly understand the logic behind it?
or is there a much simpler way i have overlooked?
any advice would be much appreciated
debs:biggrin:
 
Mathematics news on Phys.org
  • #2
I think the idea behind your approach is to consider a triangular prism.
http://www.math.washington.edu/~nichifor/Math402/prism_drawing.bmp

Given the points A,B,C of your triangle you have to set up three planes in order to get a triangular prism. Actually, you only need the normal vectors and define them to point "inwards".

Once you have those normal vectors n1, n2 and n3 you can determine
whether your point P, which you want to examine, lies within the prism and whether it lies within your triangle (x-y-plane with z=0).

I hope this is helpful.
 
  • #3
How are you given each side of the triangle? If you are given the vertices of the triangle you can write the line between two points in the form ax+ by+ c= 0. If a point is on one side of that line, ax+ by+ c will be larger than 0, if on the other, less than 0.

For each line, check to see if the given point is on the same side as the third vertex. (check to see if ax+ by+ c has the same sign for both.)

If the given point is on the same side of the line given by each pair of vertices as the third vertex, the the point is inside the triangle.
 
  • #4
thanks for the help.just with the 2nd method,you're saying all i need do is use y-y1 = m(x-x1) and use to of the vertices to calculate the slope in each case?
 
  • #5
Yes. And then see if the given point and third vertex (neither of which are on that line) give the same sign when put into y- y1- m(x-x1) (which is 0 only for points on the line).

If so, then the given point and the third vertex are on the same side of that line. If it is true for all three sides of the triangle, then the given point is inside the triangle.
 
  • #6
alternative?

thanks that's great stuff.i was thinking as well could an alternative method be to use the area of triangles.the previous procedure i had to write was calculating the area of the triangle given the three vertices.could i say that if the point p lies inside the triangle then it splits this up into three smaller triangles & the sum of these areas of the 3 small triangles must equal the area of the larger triangle if the point lies inside the large triangle.if the point p lies on one of the sides of the triangle then the area of one of the small triangles will = 0 and the area of the other two will = the area of the large triangle??if the point lies outside the triangle then the sum of the three "small" areas will larger than the area of the original triangle...??maybe line method is easier...:tongue:
 

1. How do you calculate if a point is inside or outside a triangle in 2D?

To determine if a point is inside or outside a triangle in 2D, you can use the "point-in-triangle" algorithm. This involves checking if the point lies on the same side of each of the triangle's three sides. If it does, then the point is inside the triangle. Otherwise, it is outside.

2. What information is needed to calculate if a point is inside or outside a triangle in 2D?

To calculate if a point is inside or outside a triangle in 2D, you will need the coordinates of the point and the coordinates of the three vertices of the triangle.

3. Can a point be both inside and outside a triangle in 2D?

No, a point can only be either inside or outside a triangle in 2D. If the point lies on one of the triangle's sides, it is considered inside the triangle.

4. What is the significance of calculating if a point is inside or outside a triangle in 2D?

Calculating if a point is inside or outside a triangle in 2D is important in various applications, such as computer graphics, collision detection, and geometric modeling. It helps determine if a point is contained within a specific area and can be used to make decisions in algorithms and programs.

5. Are there any alternative methods for calculating if a point is inside or outside a triangle in 2D?

Yes, there are other methods for determining if a point is inside or outside a triangle in 2D, such as using the barycentric coordinates of the point with respect to the triangle. However, the "point-in-triangle" algorithm is the most commonly used method due to its simplicity and efficiency.

Similar threads

  • Calculus and Beyond Homework Help
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
Replies
2
Views
1K
Replies
3
Views
848
  • Special and General Relativity
2
Replies
40
Views
2K
  • Introductory Physics Homework Help
Replies
8
Views
2K
  • Linear and Abstract Algebra
Replies
2
Views
5K
Replies
4
Views
4K
  • Special and General Relativity
Replies
1
Views
1K
Back
Top