geometry.shoelace

Functions

area_of_polygon(→ float)

Compute the area of a polygon. The polygon has to be planar and simple

Module Contents

geometry.shoelace.area_of_polygon(xs: list[float], ys: list[float]) float

Compute the area of a polygon. The polygon has to be planar and simple (not self-intersecting). The vertices have to be ordered in the counter-clockwise direction. https://en.wikipedia.org/wiki/Shoelace_formula

Args:

xs: list of x coordinates of the polygon vertices in counter-clockwise order ys: list of y coordinates of the polygon vertices in counter-clockwise order

Returns:

area of the polygon

>>> from math import isclose
>>> xs = [1, 3, 7, 4, 8]
>>> ys = [6, 1, 2, 4, 5]
>>> isclose(area_of_polygon(xs, ys), 16.5)
True