Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for fitting objects in a space

I have a collection of different sized squares and rectangles that I want to fit together using PHP into one large square/rectangle. The squares are usually images that I want to make into a montage - but sometimes they are simply math objects.

Are there any PHP algorithms for this and what is this type of thing called?

Update: After more searching I think what I want is called the bin packing problem. However, I would also like to add a certain amount of randomization for certain types of packing problems (like images) to allow human interest.

like image 772
Xeoncross Avatar asked Jul 13 '11 16:07

Xeoncross


1 Answers

2D Bin packing is NP-hard problem. There are however approximation algorithms.

Look at this code (and explanation). It contains multiple algorithms and there is a GUI:

Solving the 2D Packing Problem

like image 105
Petar Ivanov Avatar answered Nov 20 '22 07:11

Petar Ivanov