Cross Multiplication
Walk along the side of the triangle clockwise to determine whether the vertex is on the right side of each edge (which can be determined by cross multiplication). If the vertex is on the right side of each edge, it is within the triangle, otherwise it is outside the triangle. ThisAlgorithmOnly triplicate multiplication is used. Division operations and trigonometric functions and root numbers are not used. Therefore, the efficiency and accuracy are high (no floating point error ).
Set the triangle to three points A (x1, Y1) B (X2, Y2) C (X3, Y3), known points M (x, y ),
1. first obtain the three vectors Ma, MB, MC.
2. Calculate Ma x mb, MB x MC, MC x Ma (x table cross multiplication)
3. If the result of the vector cross-multiplication in these three groups is of the same number (both positive and negative), that is, the direction is the same, it indicates that the vertex M is on the same side of each triangle, that is, inside. Otherwise, it must be external!
Example:
A (0, 3) B (0, 0) C (3, 0)
M (1, 1)
MA (1,-2)
MB (1, 1)
MC (-2, 1)
Ma x mb = 3
MB x MC = 3
MC x MA = 3
N (3, 3)
Na (3, 0)
NB (3, 3)
NC (0, 3)
Na x Nb = 9
NB x NC = 9
NC x NA =-9
Based on the above rules, we can determine that M points are outside N points.