# Circle packing problem

Hi all,
I’m new to circle packing, and am stuck on what I think should be an easy task - filling a rectangular boundary with tangent circles of variable radii. I started with a tweak of an example from @DanielPiker, and at first, using a relatively “fat” rectangle as a test I thought I had succeeded. But what I need is to fill a skinny rectangle - and no matter what I do, it always ends up with very large circles clustered near the ends:

I’m trying to understand why (which is why I’m showing the mesh edges, which I thought controlled the circle radii). Clearly I missing something. Any help appreciated!
circle packed rectangle1.gh (14.1 KB)

1 Like

Hi,

The method I use for circle packing is this one (it’s also from Daniel, somewhere on the forum)

I prefer it because it allows for control of radius range and number of points. I seems to work well in your case.
Tweaking the amount of points is a bit tedious, I’ll admit.

circle packed rectangle1.gh (26.1 KB)

1 Like

I like to know that either.
Appears that if the boundary is more like a square it works as you expected.
And also on a more complex mesh, it works fine.

There is a very good tutorial dedicated to your method. May it helps.

Thank you! Your approach is completely different, and has no large-circle artifacts near the skinny ends (yay!). And now I see how it varies from the approach I happened upon. Your way allows control over circle radius and its range - but at the expense of “perfect” packing (I think). The other way is dictated by the goal of perfect packing and is able to change all the circles’ radii as needed (I think). Please let me know if I’m off base - this is very new to me.

Thanks for testing it out, and confirming my findings. And also for adding to the growing number of people thirsting to understand why it happens. @DanielPiker ?

Hi Bruce,

You’re correct that the approach using the `Collider` goal in magicteddy’s post is a quite different approach to the one using the TangentIncircles goal shown in yours and Quan Li’s post.

With the collisions approach, you set the radius for each of the circles, and the solver cannot change these, but the connectivity or which circles touch which other circles is determined by the solver bouncing things around, and won’t generally be the same as what it starts with.

With the TangentIncircles approach, you set the connectivity with the mesh you input, and the solver can’t change this, but it controls the radii, so you can’t set them or know in advance what they will end up as.

The packings produced by TangentIncircles are referred to as compact circle packings, and the possibilities are more restricted. In particular, for a given connectivity, the once we fix 2 points on the boundary, all the radii are fully determined (this is related to the Koebe–Andreev–Thurston theorem).
This means that the pattern can slide round the boundary, or ‘bunch up’ in a particular way (related to Moebius transformations - see Circle Packing in Enclosed Boundary - Unwanted Overlap - #12 by DanielPiker), but in general it’s impossible to fix more than 2 points and still have a strict circle packing.

For your shape, you can improve things by offsetting your boundary like this
circle packed rectangle2.gh (24.0 KB)
(note that the mesh vertices end up inside the shape, not on the boundary).

However, because the radii of the corner circles can’t be known in advance, anchoring them like this with a fixed offset is not ideal.
See my reply here for a better approach, which shows a way to keep stricter tangency when you have corners:

3 Likes

Thank you!

Thanks Daniel! Both for the practical fix and the explanation.