Skip to content

Instantly share code, notes, and snippets.

@d-v-b
Last active August 29, 2015 14:14
Show Gist options
  • Save d-v-b/4d05dafe1e03fccea069 to your computer and use it in GitHub Desktop.
Save d-v-b/4d05dafe1e03fccea069 to your computer and use it in GitHub Desktop.
from numpy import where,array,meshgrid, vstack
from matplotlib.path import Path
def getInteriorPoints(coords):
"""
Given a list of pairs of points which define a polygon, return a list of pairs of points interior to the polygon
"""
bounds = array(coords).astype('int')
bMax = bounds.max(0)
bMin = bounds.min(0)
path = Path(bounds)
grid = meshgrid(range(bMin[0],bMax[0]+1),range(bMin[1],bMax[1]+1))
gridFlat = zip(grid[0].ravel(),grid[1].ravel())
inside = path.contains_points(gridFlat).reshape(grid[0].shape).astype('int')
inside = where(inside)
# ugly
inside = vstack([inside[0],inside[1]]).T + bMin[-1::-1]
return inside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment