/// <summary> /// 计算闭合区域面积 /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="numPoints"></param> /// <returns></returns> double polygonArea(List<double> X, List<double> Y, int numPoints) { double area = 0; // Accumulates area in the loop int j = numPoints - 1; // The last vertex is the 'previous' one to the first for (int i = 0; i < numPoints; i++) { area = area + (X[j] + X[i]) * (Y[j] - Y[i]); j = i; //j is previous vertex to i } return area / 2; }
来自
http://www.mathopenref.com/coordpolygonarea2.html
lstPt 是按顺序的顶点坐标
var X = lstPt.Select(p => p.X).ToList(); var Y = lstPt.Select(p => p.Y).ToList(); double area= polygonArea(X, Y, lstPt.Count);