复杂多边形重心

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));
    }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值