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
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)
First, I am assuming that by saying centroid, you mean center. Next, I assume that the coord tuple is in the format: (x, y, width, height). In that case, it would be done this way:
coord = (601, 1006, 604, 1009)
centerCoord = (coord[0]+(coord[2]/2), coord[1]+(coord[3]/2))
where centerCoord would be the coordinates of the center in the format (x, y).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With