Skip to content

Instantly share code, notes, and snippets.

@janhuenermann
Last active May 21, 2021 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janhuenermann/347ffe2a9ee00bf8afc32c41503e5b74 to your computer and use it in GitHub Desktop.
Save janhuenermann/347ffe2a9ee00bf8afc32c41503e5b74 to your computer and use it in GitHub Desktop.
Compute the area of a polygon
def shoelace(poly):
"""Returns the area of the polygon using the shoelace formula"""
s1 = np.sum(poly[:,0] * np.roll(poly[:,1], -1))
s2 = np.sum(poly[:,1] * np.roll(poly[:,0], -1))
return np.absolute(s1 - s2) / 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment