Hi,
There is a polygon (aPlg:={{X,Y},{X,Y},,,{X,Y}}). How can I determine that a point (aPnt={X,Y}) belongs to this polygon?
I have tried several algorithms, but they all give the wrong result
FUNCTION IsPointInPolygon(x, y, poly)
LOCAL isInside := .F.
LOCAL numVertices := Len(poly)
FOR i:=1 TO numVertices
LOCAL j := Mod(i, numVertices) + 1
IF ((poly[i][2] > y) <> (poly[j][2] > y)) AND (x < (poly[j][1] - poly[i][1]) * (y - poly[i][2]) / (poly[j][2] - poly[i][2]) + poly[i][1])
isInside := .NOT. isInside
ENDIF
NEXT
RETURN isInside
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 83 guests