如何计算点的arylylist的质心

时间:2013-09-03 12:08:01

标签: java arraylist points centroid

我试图分别从ArrayList的点添加所有x和y坐标。

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



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

如何找到质心?

2 个答案:

答案 0 :(得分:20)

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

答案 1 :(得分:0)

"scripts": {
    "prestart": "d2-manifest package.json manifest.webapp",
    "start": "webpack-dev-server",
    "test": "echo Everything probably works great\\! ## karma start test/config/karma.config.js --single-run true",
    "build": "rm -rf build && set NODE_ENV=production webpack --progress && npm run manifest",
    "postbuild": "cp -r src/i18n icon.png ./build/",
    "validate": "npm ls --depth 0",
    "manifest": "d2-manifest package.json build/manifest.webapp",
    "deploy": "npm run build && mvn clean deploy",
    "lint": "echo Looks good."
  }

}