如何填补较小的正方形/长方形正方形?正方形、长方形、较小

2023-09-11 00:26:28 作者:向前进

在我工作的办公室,我们是不允许粉刷墙壁,所以我决定出去帧正方形和长方形,附加一些漂亮的布给他们,并安排他们在墙壁上。

In my office at work, we are not allowed to paint the walls, so I have decided to frame out squares and rectangles, attach some nice fabric to them, and arrange them on the wall.

我想写一个方法,将我的输入尺寸(9'×8'8)和最大/最小尺寸(1×3',2',4',等..),并生成一个正方形和长方形的随机模式,填补了墙上。我试着用手这样做,但我只是不开心,我得到的布局,它需要我想'随机'的布局,每次约35分钟。

I am trying to write a method which will take my input dimensions (9' x 8' 8") and min/max size (1' x 3', 2', 4', etc..) and generate a random pattern of squares and rectangles to fill the wall. I tried doing this by hand, but I'm just not happy with the layout that I got, and it takes about 35 minutes each time I want to 'randomize' the layout.

推荐答案

一个解决方案是先从X * Y广场和随机合并的广场一起,形成矩形。你想给不同的权重不同尺寸的正方形,以保持算法从刚刚结束与微小的矩形载荷(即大的矩形也许应该有被钦点为合并,直到他们得到太大的机会较高)。

One solution is to start with x*y squares and randomly merge squares together to form rectangles. You'll want to give differing weights to different size squares to keep the algorithm from just ending up with loads of tiny rectangles (i.e. large rectangles should probably have a higher chance of being picked for merging until they get too big).