Place random non-overlapping rectangles on a panel

后端 未结 5 930
别那么骄傲
别那么骄傲 2020-12-05 11:44

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 position

5条回答
  •  长情又很酷
    2020-12-05 12:14

    Here is a decent article on 2d packing algorithms: http://www.devx.com/dotnet/Article/36005

    You'll generally want some sort of algorithm using heuristics to achieve decent results. A simple (but non-optimal) solution would be the first fit algorithm.

提交回复
热议问题