0

I have to find the exact centroid of multiple rectangles (Minimum Bounded Rectangle). Let I have, 3 rectangles and their co-ordinates for the maximum and minimum points

1st rectangle's minimum point (x1,y1) , maximum point (x2,y2)

2nd rectangle's minimum point (x3,y3) , maximum point (x4,y4)

3rd rectangle's minimum point (x5,y5) , maximum point (x6,y6)

I quick solution come over my mind is , I will find possible list of centroids by considering combinations of this 6 points and then take the minimum bounded rectangle of those centroids. It will give me a rectangle R , the centroid of that rectangle is my real centroid.

For example , a combination is (x1,y1)+(x3,y3)+(x5,y5) , another combination is (x1,y1)+(x3,y3)+(x6,y6) etc enter image description here

But i am confused will it give me the real centroid ? Is there any other way to find the centroid ?

web2dev
  • 557
  • 10
  • 28
  • This might help: http://stackoverflow.com/questions/9031041/calculate-minimum-bounding-rectangle-of-2d-shape-by-coordinates – shree.pat18 Jun 29 '14 at 17:10
  • Thanks, but this only shows how to find the Box containing all the points, does not answer my question – web2dev Jun 29 '14 at 17:31
  • @Nusrat I am very confused with terminology because bound-area is area that encapsulate the sub objects (not what your image shows). also what exactly do you mean by centroid? rectangle that has the same gravitational pull from far enough distance perhaps? like center of mass point analogy (this shows your image) or something completely different? Sorry for silly questions but I could lost something in translation and may be also others like me too ... – Spektre Jun 30 '14 at 08:07

1 Answers1

0

I share Spektre's confusion on the problem statement. But if you just want the centroid of the point-set defined by the rectangles, here's how to do it:

If Ai is the area of rectangle i, and Ci is the centroid of rectangle i, then the centroid of all the rectangles taken together is just:

Sum(i = 1..n; Ai Ci)/Sum(i = 1..n; Ai)

The area and centroid of each rectangle is easy to compute from basic geometry.

You can think of each rectangle as having all it's mass (same as the area if we assume unit density). Then we just need the mass-weighted average of those points.

Codie CodeMonkey
  • 7,669
  • 2
  • 29
  • 45