Arranging circles in data visualisation

限于喜欢 提交于 2019-12-04 02:01:48

问题


For my data visualisation I need to arrange various sized circles into a compact area - rectangle or circle. (See this and this example.)

In theory it is a two-dimensional-irregular-cutting-stock-problem but I would like to avoid going that way. You can find similar visualisations all over the web and I doubt they use any rigorous math.

All I need is the circles to appear to be arranged in some orderly fashion (with approximately same distance between them). There must be an easier way than cutting stock math. With some exaggeration I can even imagine how 2D physics engine could use gravity to make the circles fall into a container of desired shape.

I will be thankful for any advice.


回答1:


The problem you're trying to solve is called "circle packing". Finding optimal packing densities in various shapes does indeed require rigorous math. However I was able to find some relatively simple opensource examples of circular packing algorithms.

http://wonderfl.net/c/fNNF

http://www.codeproject.com/Articles/42067/2D-Circle-Packing-algorithm-ported-to-C




回答2:


Checkout d3.js; see http://mbostock.github.com/d3/ex/pack.html.




回答3:


If you are not looking for the best solution, but just any decent solution, the iterative/physics approach should work: Place all circles, and apply a pushing force to each pair of circles until they do not overlap any more, or your loop runs out. (You will not have a way to determine if the circles fit in your area, so make sure the routine terminates)

If you want the circles to stick together, then apply an attracting force to any pair of circles that do not overlap.



来源:https://stackoverflow.com/questions/7121126/arranging-circles-in-data-visualisation

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