KANGAROO2 Circle Packing - Different sized circles

I’ve got some circles to nest onto a rectangular sheet and thought I’d try using K2 - I’m on R5 too btw.

I can get the centres of the circles to stay inside the rectangle and the circles to collide with each other but I can’t get the circles to collide with the rectangle and each other…

Unfortunately the Grab component doesn’t work on my 32bit laptop as I’ll probably need this to shuffle the circles into a nice nest but I’m still interested to see if it’s possible to nest the circles within the rectangle?NEST_CIRCLES.gh (14.7 KB)

Seriously @martynjhogg? Does everyone need their own “Personal Jesus”?


Fudged it with one rectangle for each circle radius…


1 Like

Thanks for that @Joseph_Oster I’ve read those posts and don’t believe there is one that answers this particular problem.

There’s circle packing on surfaces, circle packing with different rads from images, circle packing within borders with same sized spheres… it’s a circle packing jungle out there but I couldn’t find an example of packing different sized, known rads onto a fixed boundary.

Prove me wrong, perhaps I missed one.

It’s true that the topic of ‘circle packing’ actually covers a huge range of different topics. I’ve been trying for a while now to write a comprehensive guide to circle packing with Kangaroo, but there are just so many variations.
Ken Stephenson has focused most of his research career on circle packings and written a whole book on it, and that’s mostly on a quite specific mathematical definition of what constitutes a circle packing, whereas typically designers use the term in an even broader sense to refer to all sorts of approximate packings.

That said, here the discussion that Joseph links to above probably does contain the key component you need:

The custom ‘SphereCurveCollide’ goal in that definition lets you collide different sized spheres with a boundary without having to make a separate offset curve for every radius.


To be honest, I’d skimmed past that post in the search results because I followed it when it was current and remembered it as being related to same sized circles. I guess the search for circle packing specifics will always be a long one until your guide to circle packing hits the shelves!
I’ll try that custom SphereCurveCollide though.

NEST_CIRCLES2.gh (14.1 KB)

1 Like

NEST_CIRCLES3.gh (17.0 KB)
…and here’s one that includes the curve containment in the same goal


With the grab for rearrangement this makes a challenging puzzle.
circlenestpuzzle.gh (17.6 KB)
What’s the smallest square anyone can fit this set of circles inside?
I got it down to 1965, but surely lower is possible.


So the actual challenge, if you are interested, is to nest 3 sets of the circles into 5 sheets of 1220 x 2440mm.

I was thinking something like this but with 3 sets of the circles…

I wonder if this could be the basis of some AI nesting software… Current nesting software seems to be brute force, try every iteration or just start at bottom left and place parts in order of area into the corner.

This is just circles so simple in terms of rotating parts to fit better but I like the way you can shuffle parts by eye and then let the circle packing take over.

It was often quite easy to beat the nesting software by eye on one or 2 sheets worth of parts as the human eye is good at this sort of problem. Often the nesting software is used mostly for time saving or avoiding tedious operations but actual material efficiency is not always crucial.

Maybe the combinations needed to get a good nest are less here as it would be a few different strategies for how to drop the initial layout into the sheets rather than every possible combination?

It beats current nesting software for enjoyment anyway!

If anyone has one of the nesting plugins, please try Daniel’s puzzle above… can you nest all the parts onto the 1965x1965 square or smaller and how long does it take to do that?


This page might provide some clues

Hi Daniel,
Thanks for your sharing. Base on your gh file, I wonder if we can add 2D close curve acts like a “vaccum bag” to achieve a minimal 2D bounday for the circles (see my hand sketch)?

Thanks for any suggestion!

circlenestpuzzle.3dm (31.5 KB) circlenestpuzzle.gh (37.9 KB)

Here’s one tensioning a cable around the outside
wrapcircles.gh (16.6 KB)

This way the boundary will form a convex hull of the circles - if you want the boundary to also pull into the concave parts then you’ll need a version with 2d pressure.


There was a component called AlphaShape which would allow the concave boundary between shapes like a vacuum form but I can’t find it on Food4Rhino…


Also, I can’t get it to work on R7

It is out there on this forum if you search alpha shape…

Alpha Shapes 2D

that link from this discussion…

ah… it was on the Milkbox group on the old forum and by @MateuszZwierzycki I think

Here’s a version using 2d pressure to do a vacuum form which pulls the circles together
wrapcircles2.gh (23.2 KB)


Great, thanks Daniel!!

I have done a minor change to the GH, I want to predefine the circle radius and add a grab force to it. But don’t know why the whole bag tend to ‘flow’ to the y axis direction…How can I keep my bag not to flow to one direction, so I can manually adjust the circles and bag’s shape and location?

wrapcircles3.gh (21.1 KB)

It looks like this drifting issue is caused by something unbalanced in the Area goal.
Here’s a version that uses a simpler 2d pressure to avoid this.
There can still be small amount of drift from the collisions too, so I’ve also added a weak PlasticAnchor (which acts as a sort of static friction).

wrapcircles4.gh (26.5 KB)


Thanks Daniel, but for some reason I cannot get your script running…
Do I need to install any plug-ins?
When open your file, it shows this

You need to tell it where your copy of KangarooSolver.dll is installed.
Either when the error pops up on opening, or by right clicking the red script component and selecting Manage Assemblies.

This file is part of Rhino, and if you have multiple versions of Rhino installed, you need to reference the one from the version you are currently running.

I think this will usually be one of these directories:

C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Components

C:\Program Files\Rhino WIP\Plug-ins\Grasshopper\Components
(if you first installed v7 when it was a WIP)

C:\Program Files\Rhino 7\Plug-ins\Grasshopper\Components

C:\Program Files\Rhino 8 WIP\Plug-ins\Grasshopper\Components

1 Like