Last active
May 21, 2021 00:20
-
-
Save janhuenermann/347ffe2a9ee00bf8afc32c41503e5b74 to your computer and use it in GitHub Desktop.
Compute the area of a polygon
This file contains 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 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