开发者

Arranging circles in data visualisation

开发者 https://www.devze.com 2023-03-29 12:13 出处:网络
For my data visualisation I need to ar开发者_开发百科range various sized circles into a compact area - rectangle or circle. (See this and this example.)

For my data visualisation I need to ar开发者_开发百科range 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.


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消