Compute the centroid of a rectangle in python

Sami picture Sami · Feb 1, 2017 · Viewed 7k times · Source

I want to compute the centroid of rectangle, The coordinates of rectangle are as follows:

co_ord = (601, 1006,604, 1009)  ## (xmin,ymin,xmax,ymax)

Can someone point to an easy way. Thanks

Answer

Patrick Haugh picture Patrick Haugh · Feb 1, 2017

The centroid of a rectangle with opposite corners (x1, y1) and (x2, y2) lies at the center of that rectangle ((x1+x2)/2, (y1+y2)/2)