/**
* Computes the new positions of centroids for all clusters
*
* @param clusters
* Cluster assignment
* @param k
* number of clusters
* @return New centroid positions
*/
private static Point2D[] computeCentroids(int[] clusters, int k) {
Point2D[] centroids = new Point2D[k];
for (int j = 0; j < centroids.length; j++) {
double sumX = 0;
double sumY = 0;
int count = 0;
for (int i = 0; i < clusters.length; i++) {
if (clusters[i] == j) {
sumX += points[i].getX();
sumY += points[i].getY();
count++;
}
}
centroids[j] = new Point2D.Double(sumX / count, sumY / count);
}
return centroids;
}