Similarly, point O and point B are on the same side of straight line AC; point O and point A are on the same side of straight line BC.
If the above three conditions are met, point O is within △ABC.
Personally, I prefer this method because it only contains four arithmetic operations and size judgment, and does not involve operations such as trigonometric functions and square roots, so it is faster. If there is a better way, please advise.
Can be processed through Barycentric coordinate system. Reference link: https://en.wikipedia.org/wiki...
Suppose the point to be tested is (x0, y0), and the three points of the triangle are (x1, y1), (x2, y2), (x3, y3)
According to the definition of center of gravity coordinates:
x0 = a * x1 + b * x2 + c * x3
y0 = a * y1 + b * y2 + c * y3
a + b + c = 1
where a b c are three coefficients respectively. If and only if a b c are both greater than or equal to 0 and less than or equal to 1, point (x0, y0) is within the triangle formed by point (x1, y1), point (x2, y2) and point (x3, y3).
From the above definition, we can get the solution of a b c:
This is not simple For example, point x has three angles a, b, and c of a triangle x is the vertex of an angle. If the sum of the three angles axb bxc cxa is 360 degrees, then point x is within the triangle
There are many articles Search them http://www.cnblogs.com/baie/a...
Very common questions in computational geometry
There are
△ABC
and pointO(x, y)
. Let the triangle vertex coordinates be: A(x1,y1), B(x2,y2), C(x3,y3)Point O is in △ABC, and point O and point C are on the same side of straight line AB, then:
Similarly, point O and point B are on the same side of straight line AC; point O and point A are on the same side of straight line BC.
If the above three conditions are met, point O is within △ABC.
Personally, I prefer this method because it only contains four arithmetic operations and size judgment, and does not involve operations such as trigonometric functions and square roots, so it is faster. If there is a better way, please advise.
Can be processed through Barycentric coordinate system.
Reference link: https://en.wikipedia.org/wiki...
Suppose the point to be tested is (x0, y0), and the three points of the triangle are (x1, y1), (x2, y2), (x3, y3)
According to the definition of center of gravity coordinates:
where a b c are three coefficients respectively. If and only if a b c are both greater than or equal to 0 and less than or equal to 1, point (x0, y0) is within the triangle formed by point (x1, y1), point (x2, y2) and point (x3, y3).
From the above definition, we can get the solution of a b c:
Written in JS method:
This is not simple
For example, point x has three angles a, b, and c of a triangle
x is the vertex of an angle. If the sum of the three angles
axb bxc cxa is 360 degrees, then point x is within the triangle
There are many articles
Search them
http://www.cnblogs.com/baie/a...