Skip to content

Instantly share code, notes, and snippets.

@altsoph
Created June 7, 2020 18:05
Show Gist options
  • Save altsoph/7d94fdab21b3ba1b3cf10fe5f3e3f7c0 to your computer and use it in GitHub Desktop.
Save altsoph/7d94fdab21b3ba1b3cf10fe5f3e3f7c0 to your computer and use it in GitHub Desktop.
# pip install shapely
from shapely.geometry.polygon import Polygon
def check(polygon, square):
polygon = Polygon(polygon)
square = Polygon(square)
return polygon.contains(square)
print( check( [(0, 0), (0, 1), (1, 1), (1, 0)], [(0.1, 0.9), (0.1, 0.9), (0.9, 0.9), (0.9, 0.1)] ) )
# > True
print( check( [(0, 0), (0, 1), (1, 1), (1, 0)], [(0.1, 1.1), (0.1, 0.9), (0.9, 0.9), (0.9, 0.1)] ) )
# > False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment