Place random non-overlapping rectangles on a panel
问题 I've a panel of size X by Y. I want to place up to N rectangles, sized randomly, upon this panel, but I don't want any of them to overlap. I need to know the X, Y positions for these rectangles. Algorithm, anyone? Edit : All the N rectangles are known at the outset and can be selected in any order. Does that change the procedure? 回答1: You can model this by a set of "free" rectangles, starting with single one with coordinates of 0,0, size (x, y). Each time you need to add one more rectangle,