【计算几何】计算任意多边形的面积
2021-03-21 19:17:00 # ACM
1
2
3
4
5
6
7
8
9
10
11
12
13
struct Point2d{
double x,y;
};

//计算任意多边形的面积,顶点按照顺时针或者逆时针方向排列
double ComputePolygonArea(const vector<Point2d> &points) {
int point_num = points.size();
if(point_num < 3)return 0.0;
double s = points[0].y * (points[point_num-1].x - points[1].x);
for(int i = 1; i < point_num; ++i)
s += points[i].y * (points[i-1].x - points[(i+1)%point_num].x);
return fabs(s/2.0);
}
Prev
2021-03-21 19:17:00 # ACM
Next