1. Call an API.
Bool ptinregion (hrgn, // handle to region int X, // X-coordinate of point int y // y-coordinate of point); hrgn createpolygonrgn (const point * lppt, // array of points int cpoints, // number of points in array int fnpolyfillmode // Polygon-filling mode );
II,
If the triangle is set to ABC, the judgment point is P area, indicating the area function.
Determine the relationship between area (PAB) + area (PAC) + area (PBC)-area (ABC) and 0.
If the value is greater than 0, it is outside the triangle.
0 is inside the triangle.
III,
Set three triangle points
A (A1, A2), B (b1, b2), C (C1, C2)
Three edge Equations
BC: Fa (x, y) = 0
AC: FB (x, y) = 0
AB: FC (x, y) = 0
Taking BC as an example, the point in the Triangle must be on the same side with the point a in BC.
So for vertex d (x, y)
In a triangle, you must first meet FA (x, y) * Fa (a1, a2)> 0
The same applies to other edges.
Therefore, you only need to compare
FA (x, y) * Fa (a1, a2)
FB (x, y) * FB (b1, b2)
FC (x, y) * fc (C1, C2)
Positive and Negative Numbers
1. All three numbers are positive: D is in the triangle.
2. There must be at least one negative number: D is outside the triangle.
3 There is only one 0, and the other two are positive numbers: on the edge of the triangle
4. There is only one zero, one positive number and one negative number: the extension line of the triangle edge is also counted outside the triangle, because 2 is satisfied.
5 has two zeros: On the vertex of the triangle
6. There cannot be 3 0, 3 negative, or 0 negative.