如何计算积分的ArrayList的心 [英] how to calculate centroid of an arraylist of points

查看:171
本文介绍了如何计算积分的ArrayList的心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从分别ArrayList的分加起来所有的X和Y coordiantes。

 公共静态的ArrayList节=新的ArrayList<点和GT;();公共点的质心(){
        点中心=新点();
            的for(int i = 0; I< knots.size();我++){
            ????????????????????
        返回中心;
}

如何找到重心??


解决方案

 公共质心点(){
    双centroidX = 0,centroidY = 0;        对于(结点:结){
            centroidX + = knot.getX();
            centroidY + = knot.getY();
        }
    返回新点(centroidX / knots.size(),centroidY / knots.size());
}

I am trying to add up all the x and y coordiantes respectively from points of ArrayList.

public static ArrayList knots = new ArrayList<Point>();



public Point centroid()  {
        Point center = new Point();
            for(int i=0; i<knots.size(); i++) {
            ????????????????????
        return center;
}

How do I find the centroid ??

解决方案

public Point centroid()  {
    double centroidX = 0, centroidY = 0;

        for(Point knot : knots) {
            centroidX += knot.getX();
            centroidY += knot.getY();
        }
    return new Point(centroidX / knots.size(), centroidY / knots.size());
}

这篇关于如何计算积分的ArrayList的心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆