Created
March 18, 2015 06:23
-
-
Save mazieres/62a2fd394063dca30212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def point_inside_polygon(coord, poly): | |
''' | |
http://www.ariel.com.au/a/python-point-int-poly.html | |
''' | |
x, y = coord | |
n = len(poly) | |
inside =False | |
p1x,p1y = poly[0] | |
for i in range(n+1): | |
p2x,p2y = poly[i % n] | |
if y > min(p1y,p2y): | |
if y <= max(p1y,p2y): | |
if x <= max(p1x,p2x): | |
if p1y != p2y: | |
xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x | |
if p1x == p2x or x <= xinters: | |
inside = not inside | |
p1x,p1y = p2x,p2y | |
return inside |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment