Skip to content

Instantly share code, notes, and snippets.

@n-bar
Created June 22, 2017 09:19
Show Gist options
  • Save n-bar/fc9f1b8fec1238c269af434f30ad60eb to your computer and use it in GitHub Desktop.
Save n-bar/fc9f1b8fec1238c269af434f30ad60eb to your computer and use it in GitHub Desktop.
Point in Polygon
# http://geomalgorithms.com/a03-_inclusion.html
# https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html
# https://ru.wikibooks.org/wiki/Реализации_алгоритмов/Задача_о_принадлежности_точки_многоугольнику
# https://github.com/gregvw/pnpoly
def inPolygon(x, y, xp, yp):
c=0
for i in range(len(xp)):
if (((yp[i]<=y and y<yp[i-1]) or (yp[i-1]<=y and y<yp[i])) and \
(x > (xp[i-1] - xp[i]) * (y - yp[i]) / (yp[i-1] - yp[i]) + xp[i])): c = 1 - c
return c
print( inPolygon(100, 0, (-100, 100, 100, -100), (100, 100, -100, -100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment