private static Point2D computePointsCentroid ( MultiPoint multiPoint ) { double xSum = 0 ; double ySum = 0 ; int pointCount = multiPoint . getPointCount ( ) ; Point2D point2D = new Point2D ( ) ; for ( int i = 0 ; i < pointCount ; i ++ ) { multiPoint . getXY ( i , point2D ) ; xSum += point2D . x ; ySum += point2D . y ; } return new Point2D ( xSum / pointCount , ySum / pointCount ) ; }
Points centroid is arithmetic mean of the input points