Sweep Line algorithm for distributing rectangles randomly with minimum overlap

74 Views Asked by At

I currently have a webpage where I randomly place rectangles of different sizes, using just randomly chosen point for their starting positions. They currently overlap a lot.

I'd like to find an algorithm to nicely distribute them randomly while minimising the overlapping, taking into account their sizes, and I don't want to use brute force (randomly place one rectangle, then one other, check for collisions, then change or place another, etc.).

This is EXACTLY the questions asked here (I'm sorry if that makes my question a duplicate), and the accepted answer, which sounds perfect to me, suggests using the sweep line algorithm. However, I have trouble understanding the accepted answer and its comments, and how to apply the sweep algorithm to this rectangles cases. In particular, I have trouble understanding what the answer means by "possible spots can be divided into rectangles", and the OP comments when trying to explain the algorithm.

Could someone explain this answer like I'm 5? Pseudocode or code is OK if necessary.

0

There are 0 best solutions below