Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I need to put as many rectangle of same size as possible inside a polygon. The algorithm can put rectangles in different orientation(angle). But they cannot overlap. This is image is an example of the end result: image of rectangles inside larger rectangle

share|improve this question
    
Any constraints on the shape of the polygon? It's also a rectangle in your illustration, which is a relatively simple case. –  eBusiness Apr 9 '12 at 12:11
    
If that's a rectangle, then perhaps google for 2D bin packing might help. If not, your problem is not NP complete for sure.. –  teodron Apr 9 '12 at 13:34
    
This is asking for backtracking for sure. –  kaoD Apr 9 '12 at 13:48
    
@eBusiness, The Polygon can be in any shape but the rectangle is in fixed size. –  user960567 Apr 9 '12 at 18:04
    
@teodron, The Polygon can be in any shape but the rectangle is in a fixed size. –  user960567 Apr 9 '12 at 18:05
add comment

1 Answer 1

up vote 3 down vote accepted

In this sample you can find an algorithm to pack small textures into a big texture, that is quite similar to your matter... and maybe a good start to solve it.

http://create.msdn.com/en-US/education/catalog/sample/sprite_sheet

EDIT:

You can use a tree, where the leafs have empty regions, and the rest of nodes have the rectangles. You can iterate deeply to get a solution.

Algoritm

At first pass, the node contains the empty region. There are four combinations for adding the rectangle, by the orientation ( Vertical, Horizontal) and the way that region will be divided.

Add the four combinations.

Choose the first child,

Try to add next rectangle, adding every combination as before

If there are no room for the rectangle go back, and test next child of this parent.

Repeat that until there is no more rectangles to add.

enter image description here

share|improve this answer
    
Thanks. I will check that. Is this work for a random polygon where I need to place rectangles in any direction? –  user960567 Apr 9 '12 at 18:12
    
This seems to be for unknown length packing. I have rectangles which lengths are fixed. –  user960567 Apr 11 '12 at 3:15
    
I think the problem would be the opposite... ;) –  Blau Apr 11 '12 at 6:58
    
I am wondering whether there is no per-existing algorithm available for fixed size. Thanks anyway. –  user960567 Apr 12 '12 at 5:36
    
What is useful for variable length size is useful for fixed length size... I don't understand what is your matter... –  Blau Apr 12 '12 at 9:06
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.