Object Positioning Algorithm

穿精又带淫゛_ 提交于 2019-12-03 14:27:56

From a brief search in the internet, it seems that optimal rectangle packing is an NP-hard problem. I would guess that smart people in the academia found some approximation algorithms for that, so it is an option for googling.

But I would try to make the simple method work first:

  1. Divide your objects into sizes according to their width
  2. Try placing them line-by-line from the largest to the smallest.

My guess is that in many cases this naive solution will work.

If I understand the question, it sounds like you are looking for an "optimal" bin packing algorithm (aka the Knapsack Problem). That's an NP-Complete problem, although your description sounds like you can probably brute-force your way to an optimal solution.

I know this isn't a specific answer to your question, but it may be useful to research and/or dig into the graphviz source code. graphviz offers a number of layout models, including neato, which attempts to minimize a global energy function.

Wikipedia has some pseudo-code for force-base algorithms.

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