[Math] How to prove a point is within a triangle, given three other points

geometrytriangulationtrigonometry

Could someone please explain the formula behind this, and then provide an example of how to do this? Basically I have 4 points, each with a longitude and latitude number. (They make a polygon quad, so a square or rectangle, in the shape of two triangles.) I then have a user's point. This is their location, also in the form of latitude and longitude coordinates. What is the process I need to determine if that point is INSIDE the square (or two triangles)?

For example, I may have four points:

Point A: x = 5, y = 0

Point B: x = 10, y = 0

Point C: x = 4, y = 3

Point D: x = 10, y = 3

User Point Z: x = 7, y = 2

If I were to draw this out on a graph, I can see that "Z" is clearly inside the polygon. However, how can I prove this with math, rather than relying on graph paper?

Thank you!

Best Answer

You can express the position of the fourth point in Barycentric Co-ordinates by reference to the first three. If these are all positive the fourth point lies in the triangle defined by the first three. If one co-ordinate is zero, the fourth point lies on a side, and if two are zero, the fourth is at a vertex (ie one of the original points).

Related Question