java – 如何计算点的arraylist的质心
作者:互联网
我试图分别从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;
}
我怎样才能找到质心?
解决方法:
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());
}
标签:points,java,arraylist,centroid 来源: https://codeday.me/bug/20191008/1871214.html