Need rectangle packing algorithm

My problem: “There is an arbitrary amount of arbitrary sized rectangles. How to put them in a smallest possible rectangle?”

http://freehackers.org/%7Etnagy/linpacker/linpackerng-tb.png

This is the so called 2D Binary Packing problem, or Rectangle Packing problem, but til now I have found only this program in picture (LinPacker), but the algorithms there are not available to implement in Python. Can anyone help me? This is needed for a city planning project, the rectangles represent existing quarters.

Haven’t tested out the code, but a short googling gave me:

Its not python, but it should be relatively easy to translate if that’s what you’re looking for…

There is box packing code already in Blender for the UV tools. I remember ideasman originally wrote it in Python, for the lightmap unwrap script, but there’s also a ‘pack islands’ command in the UV editor that’s built in. Maybe scripts just call that now, i’m not sure. But check out the unwrap scripts bundled with Blender, for sure.

Thanks, i’ll try to implement this one you found: http://www.blackpawn.com/texts/lightmaps/default.html

The idea looks quite easy, and I think it is better to try do-it-yourself. I’ll post my progress report when I get something ready.