How to check if point X,Y is within a polygon.
Point in polygon
Apparently this solution involves checking how many times you cross
a line to pass from point X,Y to the outer edge of the screen.
I honestly have never tried reading the code properly to try to
understand the concept, I just know that it seems to work !
function PtInPoly(const Points: Array of TPoint; X,Y: Integer): Boolean;
J : Integer;
Result := False;
Count := Length(Points);
J := Count-1;
for I := 0 to Count-1 do begin
if ((Points[I].Y <=Y) and (Y < Points[J].Y)) or
((Points[J].Y <=Y) and (Y < Points[I].Y)) then
if (x < (Points[j].X - Points[i].X) * (y - Points[i].Y) /
(Points[j].Y - Points[i].Y) + Points[i].X) then
Result := not Result;
J := I;