Centroid of a set of positions on a toroidally wrapped (x- and y- wrapping) 2D array?
I've done this before for Ramachandran plots. I will check but I seem to remember the algorithm I used was:

Assume that your Euclidian area has an origin at (0,0)
Shift all the points in a set so that they are fully within the area
Calculate the centroid
Shift the centroid back by the reverse of the original

So, say your points are split across the X axis, you find the minimum X-coordinate of the point set that is larger than the midpoint axis of the area. Then find the distance d to the edge on the Y axis. Then shift the entire cluster by d.
I have a flat Euclidean rectangular surface but when a point moves to the right boundary, it will appear at the left boundary (at the same y value). And visa versa for moving across the top and bottom boundaries. I'd like to be able to calculate the centroid of a set of points. The set of points in question are mostly clumped together.
I know I can calculate the centroid for a set of points by averaging all the x and y values. How would I do it in a wrap-around map?