# KANGAROO2 Circle Packing - Different sized circles

**URL:** <https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878>\
**Category:** Grasshopper\
**Tags:** kangaroo-2\
**Created:** [October 4, 2019, 2:59pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878 "2019-10-04T14:59:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [October 4, 2019, 2:59pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/1 "2019-10-04T14:59:22Z")

</div>

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…

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/a/a/aaf19f7d2eea360d11cadcc5e76d354afd6ccd3f.png)

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](https://discourse.mcneel.com/uploads/short-url/jSNz4GQGvyjM8gv7f7fIRIOsjT9.gh) (14.7 KB)

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [October 4, 2019, 3:06pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/2 "2019-10-04T15:06:38Z")

</div>

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

[https://discourse.mcneel.com/search?q=KANGAROO2%20Circle%20Packing](https://discourse.mcneel.com/search?q=KANGAROO2%20Circle%20Packing)

[![](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/6/a/f6a280da199ea1808ac83f6df4efdb37356e99b1.jpeg "Depeche Mode - Personal Jesus (Official Video)") ](https://www.youtube.com/watch?v=u1xrNaTO1bI)

> [@Circle Packing Perforations](https://discourse.mcneel.com/t/circle-packing-perforations/86499):
>
> I’ve read just about every circle packing post on here and the original Grasshopper forum. So many ways to skin that cat. The method I’ve latched onto uses a C# script from god knows where/when. It’s just a little buggy compared to newer methods and I’m not sure how to update it or find a post-Kangaroo 2 alternative. This is my simple perforation definition. [image] [circle pack perforation.gh](https://discourse.mcneel.com/uploads/short-url/3tjJEKkGHGeFuixq1mpxytj0HRN.gh) (21.4 KB) [This Circle Packing](https://github.com/Dan-Piker/Kangaroo-examples/blob/master/collisions_and_packing/CirclePackOnSurface.gh) definition below by @DanielPiker isn’t as tight around the b…

> [@Circle packing on curved surface](https://discourse.mcneel.com/t/circle-packing-on-curved-surface/81658):
>
> Hi, I am trying to apply the circle packing study on a curved surface. The center of the circles are points on the surfaces. But the circle are not oriented as the surface. Do you know how to solve the issue Thanks in advance [circle packing curved surface.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/9/4/94041bad0f919a32c424c83e0f583621f36a3813.gh) (28.2 KB)

---

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [October 4, 2019, 3:09pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/3 "2019-10-04T15:09:51Z")

</div>

Fudged it with one rectangle for each circle radius…

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/d/1d649cc4301b11726b592de610957656ddf55399.png)

[NEST\_CIRCLES.gh](https://discourse.mcneel.com/uploads/short-url/p60LM9pFswU472ygiQugzbNvXDt.gh) (14.8 KB)

---

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [October 4, 2019, 3:13pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/4 "2019-10-04T15:13:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [October 4, 2019, 3:34pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/5 "2019-10-04T15:34:22Z")

</div>

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](http://www.circlepack.com/) 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:

> [@Circle Packing Perforations](https://discourse.mcneel.com/t/circle-packing-perforations/86499/7):
>
> Thanks. Took me awhile to realize that there is a second Multiplication component in the model, but the value of its ‘B’ input isn’t visible? So I improvised with a slider: [circle\_pack\_perforation2\_R5.gh](https://discourse.mcneel.com/uploads/short-url/u6F6ZK0ruFrOPvH9btSmJo3Mqe2.gh) (25.2 KB)

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.

---

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [October 4, 2019, 3:39pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/6 "2019-10-04T15:39:04Z")

</div>

Thanks!  
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.

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [October 4, 2019, 3:42pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/7 "2019-10-04T15:42:52Z")

</div>

[NEST\_CIRCLES2.gh](https://discourse.mcneel.com/uploads/short-url/dfHxHbtnXCf2GSgTKFSWfTWUsFJ.gh) (14.1 KB)

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [October 4, 2019, 4:23pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/8 "2019-10-04T16:23:10Z")

</div>

[NEST\_CIRCLES3.gh](https://discourse.mcneel.com/uploads/short-url/dGoHxFtDqs4XD8WfhuDbr1Y6mO5.gh) (17.0 KB)  
…and here’s one that includes the curve containment in the same goal

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [October 4, 2019, 5:12pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/9 "2019-10-04T17:12:09Z")

</div>

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/a/1a6474fa43529bc632b3278431a1644b5818ac5b.png)  
With the grab for rearrangement this makes a challenging puzzle.  
[circlenestpuzzle.gh](https://discourse.mcneel.com/uploads/short-url/pPm4G7dlTlZS4gMXjZBPJwkbKeJ.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.

---

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [October 4, 2019, 11:23pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/10 "2019-10-04T23:23:12Z")

</div>

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…  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/4/0/407f4c8ad3472d33a66463ca7f711b3178497aaa.png)

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?

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [October 4, 2019, 11:43pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/11 "2019-10-04T23:43:42Z")

</div>

This page might provide some clues  
[http://hydra.nat.uni-magdeburg.de/packing/](http://hydra.nat.uni-magdeburg.de/packing/)

---

<div class="post-metadata">

**Author:** ![Jack\_Zeng](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jack_zeng/32/761863_2.png) [@Jack\_Zeng](https://discourse.mcneel.com/u/Jack_Zeng)\
**Post date:** [March 24, 2021, 4:04am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/12 "2021-03-24T04:04:09Z")

</div>

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!

 ![F56338472B93AD4C1DFD9CC6C5F8D73C](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/f/7/c/f7c1b5253f0e65667751cf79195ac5e50839d447.jpeg) [circlenestpuzzle.3dm](https://discourse.mcneel.com/uploads/short-url/gGw7vqGn0SwFVyB2p4CAsae4Qxw.3dm) (31.5 KB) [circlenestpuzzle.gh](https://discourse.mcneel.com/uploads/short-url/tYrSLpmzQD9QlQ1TSw3Qttyjxg1.gh) (37.9 KB)

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [March 24, 2021, 10:32am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/13 "2021-03-24T10:32:06Z")

</div>

Here’s one tensioning a cable around the outside  
[wrapcircles.gh](https://discourse.mcneel.com/uploads/short-url/zcGHPl1PJrw0hTE0uIs1YbxI2JA.gh) (16.6 KB)  
 ![circwrap](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/4/7/a47a3586a291b7f07dbdec6277e519b628ddda83.gif)

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.

---

<div class="post-metadata">

**Author:** ![martynjhogg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/martynjhogg/32/513395_2.png) [@martynjhogg](https://discourse.mcneel.com/u/martynjhogg)\
**Post date:** [March 24, 2021, 10:40am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/14 "2021-03-24T10:40:05Z")

</div>

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…

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/e/9/c/e9c24eb3af950a80f5bee5989f937d6d04b8dcc0.png)

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](https://doc.cgal.org/latest/Alpha_shapes_2/index.html)

that link from this discussion…  
[https://discourse.mcneel.com/t/alpha-shape-3d/60651](https://discourse.mcneel.com/t/alpha-shape-3d/60651)

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

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [March 24, 2021, 10:43am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/15 "2021-03-24T10:43:15Z")

</div>

Here’s a version using 2d pressure to do a vacuum form which pulls the circles together  
 ![wrapcircs2](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/c/2/cc254f37afe5cc00b77424c8277e02c7f11c9a3f.gif)  
[wrapcircles2.gh](https://discourse.mcneel.com/uploads/short-url/3aUgusT5OOq2qlBvwQr5yeUvV0E.gh) (23.2 KB)

---

<div class="post-metadata">

**Author:** ![Jack\_Zeng](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jack_zeng/32/761863_2.png) [@Jack\_Zeng](https://discourse.mcneel.com/u/Jack_Zeng)\
**Post date:** [March 24, 2021, 10:45am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/16 "2021-03-24T10:45:28Z")

</div>

Great, thanks Daniel!!

---

<div class="post-metadata">

**Author:** ![Jack\_Zeng](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jack_zeng/32/761863_2.png) [@Jack\_Zeng](https://discourse.mcneel.com/u/Jack_Zeng)\
**Post date:** [March 24, 2021, 11:21am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/17 "2021-03-24T11:21:53Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/mzJsPINVX9U8YWtN9QOhSuDgC12.gh) (21.1 KB)

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [March 24, 2021, 11:43am UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/18 "2021-03-24T11:43:35Z")

</div>

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).

![wrapgrab](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/0/3/303f4bc2bfaff82080b31287dc30c095e3d31f15.gif)  
[wrapcircles4.gh](https://discourse.mcneel.com/uploads/short-url/gxt3z9jb3ow8t7QkDsxqbhyGZNL.gh) (26.5 KB)

---

<div class="post-metadata">

**Author:** ![Jack\_Zeng](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/jack_zeng/32/761863_2.png) [@Jack\_Zeng](https://discourse.mcneel.com/u/Jack_Zeng)\
**Post date:** [March 24, 2021, 1:07pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/19 "2021-03-24T13:07:50Z")

</div>

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

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/2/1/a218488ed77104cdaa9d1c4967a6e9682c3e757c.png)  
 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/1/0/c102023287381148f94177bacd224c1d56f0363a.png)

---

<div class="post-metadata">

**Author:** ![DanielPiker](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/danielpiker/32/666337_2.png) [@DanielPiker](https://discourse.mcneel.com/u/DanielPiker)\
**Post date:** [March 24, 2021, 1:12pm UTC](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878/20 "2021-03-24T13:12:04Z")

</div>

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`

[Next page](https://discourse.mcneel.com/t/kangaroo2-circle-packing-different-sized-circles/89878.md?page=2)
