No more classic algorithms:
// Function: determines whether the vertex is inside the polygon.
// Method: calculates the intersection between the horizontal line and each side of the polygon.
// Conclusion: the single-side intersection is an odd number!
// Parameters:
// A point specified by point P
// Coordinates of each vertex of the lppoint ptpolygon polygon (the first and last vertex may be inconsistent)
// Int ncount the number of points on the Polygon
Bool ptinpolygon (point P, lppoint ptpolygon, int ncount)
{
Int ncross = 0;
For (INT I = 0; I <ncount; I ++)
{
Point P1 = ptpolygon [I];
Point P2 = ptpolygon [(I + 1) % ncount];
// Solve the intersection of Y = P. Y and P1P2
If (p1.y = p2.y) // P1P2 is parallel to Y = y
Continue;
If (P. Y <min (p1.y, p2.y) // The intersection is over the P1P2 extension line.
Continue;
If (P. Y> = max (p1.y, p2.y) // The intersection is over the P1P2 extension line.
Continue;
// Obtain the X coordinate of the intersection point --------------------------------------------------------------
Double x = (double) (p. y-p1.y) * (double) (p2.x-p1.x)/(double) (p2.y-p1.y) + p1.x;
If (x> p. x)
NCross ++; // only count single-side intersections
}
// The intersection of a single side is an even number, which is outside the polygon ---
Return (nCross % 2 = 1 );
}