;

PDA

Click to See Complete Forum and Search --> : Fit many display objects of different sizes within a boundary?


iggy_the_weirdo
08-22-2009, 03:22 AM
I am currently working on an AS3 where I need to fit many differently sized display objects within a rectangular boundary without them overlapping. If you take a look at this link, http://wiffiti.com/ and take note of how the speech bubbles are able to align themselves in the swf without overlapping, this is pretty much exactly what I hope to achieve.

Can someone please point me in the right direction of an algorithm (doesn't have to be AS3) or solution to be able to achieve this, or able to explain the process that I would need to implement.

Thanks.

5TonsOfFlax
08-22-2009, 12:18 PM
You have stumbled upon an NP-hard (http://en.wikipedia.org/wiki/NP-hard) problem. It's a packing problem (http://en.wikipedia.org/wiki/Packing_problem) related to the Knapsack problem (http://en.wikipedia.org/wiki/Knapsack_problem).

The best you'll be able to do is probably use a physics simulator to iteratively reposition the items. Have each item repel the others and let them find the most stable arrangement over some iteration/time limit.

iggy_the_weirdo
08-22-2009, 09:50 PM
You have stumbled upon an NP-hard (http://en.wikipedia.org/wiki/NP-hard) problem. It's a packing problem (http://en.wikipedia.org/wiki/Packing_problem) related to the Knapsack problem (http://en.wikipedia.org/wiki/Knapsack_problem).

The best you'll be able to do is probably use a physics simulator to iteratively reposition the items. Have each item repel the others and let them find the most stable arrangement over some iteration/time limit.

Thanks 5Tons, your post is very helpful. I'll give it a crack.