Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill a square with smaller squares/rectangles?

Tags:

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.

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.

like image 931
esac Avatar asked Dec 16 '09 17:12

esac


People also ask

How many small squares fit in a large square?

Given this square, how many of these squares will it take to make up this larger square? If you put the smaller square into the larger you will see that it will take four of the smaller squares to make the larger. So we can say that the area of the larger square is four square units.

How do you find the minimum number of squares of a rectangle?

Limits: 1 <= N <= 100 and 1 <= M <= 100. Example: Let N=1 and M=2, then answer is 2 as the minimum number of squares that can be cut is 2 (the paper is cut horizontally along the smaller side in the middle).

How many rectangles are there in A4?

36 Rectangle Labels per A4 sheet 57 mm x 20 mm.


1 Answers

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

like image 59
Brian Avatar answered Jan 01 '23 21:01

Brian