Grouping rectangles (getting the bounding boxes of rects)

Posted by hyn on Stack Overflow See other posts from Stack Overflow or by hyn
Published on 2010-12-26T03:49:19Z Indexed on 2010/12/26 3:54 UTC
Read the original article Hit count: 323

What is a good, fast way to get the "final" bounding boxes of a set of random (up to about 40, not many) rectangles? By final I mean that all bounding boxes don't intersect with any other.

Brute force way: in a double for loop, for each rect, test for intersection against every other rect. The intersecting rects become a new rect (replaced), indicating the bounding box. Start over and repeat until no intersection is detected.

Because the rects are random every time, and the rect count is relatively small, collision detection using spatial hashing seems like overkill. Is there a way to do this more effectively?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about geometry