Tiling different size rectangles

…衆ロ難τιáo~ 提交于 2019-12-09 13:01:39

问题


I am looking for some pointers to algorithms that should allow to tile with no overlap different size rectangles.

Given a set of different sized rectangles, tile them on an area of size H x W with no overlap. The objective would be to maximize the space used or conversely - minimize area of gaps. If there is not enough space, proceed on the second area of the same size and so on.

It is assumed that each rectangle's width and height are smaller than respective dimensions of the tiling area. Rectangles are not rotated or otherwise transformed - i.e. their sides are either horizontal or vertical.

I am not looking for finished code, just curious what approaches/algorithms are the best to use to solve this problem.


回答1:


Most simple is to use a kd-tree to subdivide the tree into vertical and horizontal euklidian 2d space. Then you can pack a rectangle into one of the created space and recursively subdivide the tree. There is a Jquery treemap plugin example available online. The jquery plugin masonry can do the same but it's more like a 1d bin-packing solver. 2d bin-packing is much more complicated and can also mean to rotate rectangles. Here is an example for packing lightmaps: http://www.blackpawn.com/texts/lightmaps/default.html.




回答2:


I have one idea that could go in the right direction. The idea is to track ratio of tile area vs white area in a bounding box.

input: unordered set of input rectangles output: filled area

  1. Define empty bounding box
  2. Select such two rectangles A_i and B_j from the input set whose bounding box B contains minimal blank area ratio
  3. Update the bounding box with the two optimal boxes
  4. Put the bounding box in a corner, say (1,1)
  5. Repeat until no boxes
    1. Take a new box from the set such as the updated bounding box has minimum blank
    2. Constrain growing in horizontal or vertical direction if the bounding box width or height exceeds that of output area
    3. If it is impossible to add a new box, proceed with a new area H x W and restart the algorithm, else update the bounding box

There are still some points to define - how to best decide the place of bounding box? How to impose the bounding box growing restrictions? How to efficiently find the best bounding box?



来源:https://stackoverflow.com/questions/11724066/tiling-different-size-rectangles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!