Tiling different size rectangles

旧城冷巷雨未停 提交于 2019-12-03 15:29:55

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.

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?

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