Created
December 15, 2018 09:14
-
-
Save cyberkm/a7f881b126dc852c41ce0ff4b96149bb to your computer and use it in GitHub Desktop.
Compute area of polygon
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
Source: https://www.johndcook.com/blog/2018/09/26/polygon-area/ | |
Shoelace formula: | |
x1 y2 + x2 y3 + … xn y1 – y1 x2 – y2 x3 – … – yn x1 | |
Python implementation | |
def area(x, y): | |
n = len(x) | |
s = 0.0 | |
for i in range(-1, n-1): | |
s += x[i]*y[i+1] - y[i]*x[i+1] | |
return 0.5*s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment