Algorithm needed for distributing rectangles evenl

2019-03-31 09:31发布

I am looking for an algorithm that can help distribute different sized rectangles within a larger rectangle while minimizing overlapping.

I have looked at bin packing algorithms, but they seem to minimize the amount of space between rectangles (in my case the all of the items being packed will be squares).

I guess I want to maximize the distance between all squares and the border of the outer rectangle.

Here is an example of what I am trying to do:

Example of what I am saying

2条回答
爷的心禁止访问
2楼-- · 2019-03-31 09:45

This seems to be a generalization of the Knapsack Problem.

Dynamic programming will solve it in close to polynomial time.

查看更多
Animai°情兽
3楼-- · 2019-03-31 10:00

What if you packed them as tightly as possible, using an algorithm like the one described here, then expanded evenly to match the target enclosing rectangle?

For example, say you can pack the 3 rectangles above into a 3x2 box, and your outer box is 7x5. Then take the vector from the center of the box to the center to each rectangle, and multiply the x component by (7/3), and the y component by (5/2), and that gives the new center.

查看更多
登录 后发表回答