如何填补较小的正方形/长方形正方形? [英] How to fill a square with smaller squares/rectangles?

查看:148
本文介绍了如何填补较小的正方形/长方形正方形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

这篇关于如何填补较小的正方形/长方形正方形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆