Sub CheckPointInPolygone(polx() As Double, poly() As Double, x As Double, y As Double) As Boolean
Dim x1, y1, x2, y2, D As Double
Dim i, ni As Int
ni = 0
x1 = polx(0)
y1 = poly(0)
For i = 1 To polx.Length
If i < polx.Length Then
x2 = polx(i)
y2 = poly(i)
Else
x2 = polx(0) ' checks the last line
y2 = poly(0)
End If
If y >= Min(y1, y2) Then
If y <= Max(y1, y2) Then
If x <= Max(x1, x2) Then
If (x = x1 And y = y1) Or (x = x1 And x = x2) Then ' checks vertices and vertical lines
Return True
End If
If y1 <> y2 Then
D = (y - y1) * (x2 - x1) / (y2 - y1) + x1
If x1 = x2 Or x <= D Then
ni = ni + 1
End If
End If
End If
End If
End If
x1 = x2
y1 = y2
Next
If ni Mod 2 = 0 Then
Return False
Else
Return True
End If
End Sub