在网上发现一个很有意思且很有用的多边形面积计算公式-鞋带公式
鞋带公式的表达式为:
where
$\bullet A$ is the area of the polygon,
$\bullet n$ is the number of sides of the polygon, and $\cdot\left(x{i}, y{i}\right), i=1,2, \ldots, n$ are the ordered vertices (or “corners”) of the polygon.
参考wiki:Shoelace formula
可以理解为,是把每个顶点向x轴做垂线,每个边和坐标轴构成的梯形面积矢量和就是多边形的面积。
1. 鞋带公式实现
From: stackoverflow - calculate-area-of-polygon-given-x-y-coordinates
1 | def polygon_area(x,y): |
2. 示例1 - 计算曲线与坐标轴的面积
[计算曲线与坐标轴的面积
1 | import numpy as np |
3. 示例2 - detectron2 mask 面积
1 | def area(self): |