Circle packing with fixed radius and fixed number of circle for each radius

Hello guys,

i have an urgent question regarding circle packing, i’m trying to pack a set of circles with fixed radius (this part has been solved) however, now i’m trying to add another criteria into the script by having a fixed number of circles for each radius ( ie. 100 circles for radius A, 50 circles for radius B, and 20 circles for radius C) packed into a defined boundary.

any help is greatly appreciated.

I have uploaded my script for circle packing with fixed radius, hopefully someone can add some insights into how this could be accomplished. (14.5 KB)


You were not very far from the answer !!! Don’t forget to change the seeds of Random component in order to have differents points location, it is the reason of 255 and 25799778. But you can put 1, 2, 3 !!!


Hi,do you have any ideas how to add a boundary circle to this script?


yes if you seek a bit there are some examples on this forum and on
Kingfisher Quilling
But if you seek to put 5 different sizes there are some variables, which are the number of each species, or ratio of species. Do you want a packing with gravity …


Hi Marcin,
Here’s an updated version with Kangaroo2 (20.2 KB)

1 Like

Forgot to mention - When making this I noticed a small error causing an instability in the collisions component, so the definition above includes a scripted fix for this. When you first open it, you’ll be prompted to set the location of the referenced file and will need to tell it where your copy of KangarooSolver.dll is.


I’d missed that post - nice work!

As always wonderful results @DanielPiker. And thanks for all the good examples. I use also a lot MeshMachineStatic.
I had just some difficulties finding the location of solver on my PC with Rhino 6.0
C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Components (28.6 KB)

Here’s a version showing how you can have more different sizes.
I think it would be a pretty hard problem to find a global optimum for (in terms of minimum radii for the outer circle for a given set of circles inside), but I noticed you can often improve the packing by shrinking down the outer radius to give them a squeeze so they all overlap slightly, then bring it back up to a point where they are tangent again.
I found it interesting how if you keep doing this, it tends to push the smaller circles towards the middle.


That’s insane! Guys thank you so much. @DanielPiker your script is perfect. I am extremely grateful for your help and your time.

I was playing around with this yesterday but didn’t get it to work satisfactorily - definitely @DanielPiker’s version is much better!

In case anyone’s interested though: (22.2 KB)
( requires quite a lot of manual tweaking and dragging points about… really should get around to learning custom Kangaroo goal scripting :sweat_smile: )


Thanks for sharing - I prefer this way of controlling the numbers and radii.
By the way - the problem I found with the collisions component was that when one object was involved in multiple collisions, the vectors were being summed, but to keep it stable in the new solver what really needed to happen was for these vectors to be averaged.

With a few small changes it was possible to use this to simulate granular convection, sometimes called the ‘Brazil nut effect’ - the tendency of larger particles to rise to the top when their container is shaken, such as Brazil nuts in a box of muesli! (30.2 KB)


Great work.
Interestingly enough, this shaking principle is the operational principle for an ultrasonic particle sorter, used to sort very fine grades of abrasives (in the 600 to 50,000 mesh range), pharmaceutical particles,
Which leads to the thought, this could be used to study soil liquification during disturbance events, for example a seismic event. The vertical load (y) in your script could be reduced by effective buoyancy due to ground water, particle to particle cohesion could be modeled, containment pressure could also be added.
Great work.

Amazing! do you need kanagaroo2 plugins to complete the script?

Yes, you’ll need a current version of kangaroo to run this definition. Rhino 6 includes this, or if on rhino 5 you can get the latest from food4rhino

Very interested to take a look at this, but I get the following error message:

Error (CS0246): The type or namespace name ‘GoalObject’ could not be found (are you missing a using directive or an assembly reference?) (line 79)

I changed the assembly reference location for the KangarooSolver.dll, and made sure it was unblocked.

Any ideas?

Rhino Version 6 SR7

Because you’re using Rhino 6, make sure to reference the copy of the DLL in the Rhino folder (Program Files>Rhino6>Plug-ins>Grasshopper>Components), not the one in the roaming grasshopper libraries folder.

That solved it. Thanks.

I am having this issue at the moment, i have relinked the KangarooSolver but this still comes up. I am still getting to know Grasshopper altogether forgive me !