Java Geometry Algorithm centroid(Vector points)

Here you can find the source of centroid(Vector points)

Description

centroid

License

Open Source License

Declaration

public static Point2D centroid(Vector<Point2D> points) 

Method Source Code

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

Related

  1. botSides( Point2D.Double botLocation)
  2. bound(Point... points)
  3. boundingBox(Vector points)
  4. boundsOf(Collection points)
  5. cap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)
  6. checkPoint(Point p)
  7. checkPoint(Point point, String name)
  8. checkWinPossibility(int[][] board, Point p1, Point p2, int playerID)
  9. circleLineIntersection(double theta, double r, double h, double k, Point2D[] result)