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 ??
To find the centroid, follow these steps: Step 1: Identify the coordinates of each vertex. Step 2: Add all the x values from the three vertices coordinates and divide by 3. Step 3: Add all the y values from the three vertices coordinates and divide by 3.
In Mathematics, the centroid defines the geometric centre of a two-dimensional plane surface. It is a point that is located from the arithmetic mean position of all the points on the plane surface. Otherwise, it is defined as the average of all the points in the plane figure.
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With