Skip to content

Instantly share code, notes, and snippets.

@WiwilZ
Created March 27, 2025 13:24
Show Gist options
  • Select an option

  • Save WiwilZ/2ee97099a0da3f4cce6f2c0973cd6ad8 to your computer and use it in GitHub Desktop.

Select an option

Save WiwilZ/2ee97099a0da3f4cce6f2c0973cd6ad8 to your computer and use it in GitHub Desktop.
def calc_polygon_area(points):
assert len(points) >= 3
area = 0
for i in range(len(points) - 1):
x1, y1 = points[i]
x2, y2 = points[i + 1]
area += (y1 + y2) * (x2 - x1)
x1, y1 = points[-1]
x2, y2 = points[0]
area += (y1 + y2) * (x2 - x1)
return abs(-area * 0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment