1.任意n边形(包括凹多边形)可分为n-2个三角形,分别求得多边形
2.分别求得n-2个多边形的重心
gx=(x1+x2+x3)/3;
gy=(y1+y2+y3)/3;
3.分别求得n-2个多边形的面积
叉乘/2;
面积可正可负
4.加权平均
public static LatLong getCenterOfGravity(List<LatLong> mPoints) {
double area = 0.0;//多边形面积
double gx = 0.0;
double gy = 0.0;// 重心的x、y
List<Point> points = loc2Point(mPoints.get(0), mPoints);
Point point = points.get(0);
for (int i = 1; i <=points.size()-2; i++) {
Point point1 = points.get(i);
Point point2 = points.get(i + 1);
Vector2D vector2D = new Vector2D(point1.x - point.x, point1.y - point.y);
Vector2D vector2D1 = new Vector2D(point2.x - point.x, point2.y - point.y);
//面积
double v = vector2D.crossProduct(vector2D1) / 2;
area+=v;
//重心
double x = (point.x + point1.x + point2.x) / 3.0;
double y = (point.y + point1.y + point2.y) / 3.0;
gx+=v*x;
gy+=v*y;
}
gx=gx/area;
gy=gy/area;
return point2loc(mPoints.get(0), new Point(gx, gy));
}