Here you can find the source of centroid(Vector
public static Point2D centroid(Vector<Point2D> points)
//package com.java2s; /* // w w w . j a v a 2s .co m * Authors: Caroline Appert (caroline.appert@lri.fr) * Copyright (c) Universite Paris-Sud XI, 2007. All Rights Reserved * Licensed under the GNU LGPL. For full terms see the file COPYING. */ import java.awt.geom.Point2D; import java.util.Iterator; import java.util.Vector; public class Main { public static Point2D centroid(Vector<Point2D> points) { double sumX = 0; double sumY = 0; for (Iterator<Point2D> iterator = points.iterator(); iterator.hasNext();) { Point2D next = iterator.next(); sumX += next.getX(); sumY += next.getY(); } int length = points.size(); return new Point2D.Double(sumX / length, sumY / length); } }