How to get center of set of points using Python


Question

I would like to get the center point(x,y) of a figure created by a set of points.

How do I do this?

1
19
5/25/2013 6:29:31 PM

Accepted Answer

If you mean centroid, you just get the average of all the points.

x = [p[0] for p in points]
y = [p[1] for p in points]
centroid = (sum(x) / len(points), sum(y) / len(points))
26
12/4/2010 9:27:54 PM

I assume that a point is a tuple like (x,y).

x,y=zip(*points)
center=(max(x)+min(x))/2., (max(y)+min(y))/2.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon