Packing spheres in volume of shape

Hello,
I have some visual tests to do.
how can I get a packing of spheres inside a closed shape.
goal is to know how many spheres would fit for further build.
Ive looked around but didnt find a solution in the forums.

Example
10in x 10in x10in cube.
filled with 1in diameter spheres.
would it be 1260 spheres ?
Can grasshopper do this visually so i can change spheres diameters and box sizes ?
eventually to get sphere counts in different non box shapes or meshes


This need physics; use blender or other softwares

take a look to Bazil nut effect, maybe you can extrapolate to 3d, this files from the kangaroo examples could be helpful too.
balloondemo.gh (28.3 KB)
floorcollide.gh (13.1 KB)

Do you even need to produce the spheres for this? If you know the volume of your shape - something which can be done easily enough with GH, and you know the system of units you’re working in, then you can calculate how many unit cells it contains. Multiply this by the number of spheres per unit cell and you derive the total number spheres.

CCP has four spheres per unit cell, You specified that the sphere has a diameter =1, so r = 1/2. If the radius is 1/2 inch, then, according to the formula above, unit cell edge = sqrt(8)*(1/2) = sqrt(2). The volume of the cell is then sqrt(8). The number of cells of volume sqrt(8) in a 10 x 10 x 10 cube is 1000/sqrt(8).

numbers of spheres in volume = number of unit cells * number of spheres/unit cell = (1000/sqrt(8))4
which is 1000
sqrt(2), about 1414.

OR, more simply, if you already know the packing efficiency for the arrangement, which in this case is 74.05%, then the volume occupied by the spheres is 1000 * .7405 = 740.5 . The volume of a single sphere is 4/3* pi*(1/2)^3 = 0.5236. so the number of spheres is 740.5 /.5236 = 1414 (rounded)

http://mathworld.wolfram.com/SpherePacking.html

1 Like

I think the question isn’t clearly defined.

Do you want to know the exact number of spheres which can fit in some volume or just an approximation?

Do you want the absolute maximum number possible, or the maximum number while keeping them all in the cubic-close packed structure?

The densest possible arrangement within a given boundary isn’t necessarily just some subset of the densest arrangement in infinite space.

Consider the problem for just a single layer of spheres (ie circle packing within a boundary) - this is the densest possible packing for one ratio of circle to square size.


-so not just part of the hexagonal packing which is the densest infinite packing of circles

while for a different ratio you get this:


-which, while it is part of a hexagonal packing, doesn’t achieve the same density, because you have half circle sized gaps near the edges

You could certainly use a physics based method, and I can share some more examples with Kangaroo if that is the approach you want to take. Generally this can be a way to find a fairly dense sphere packing, but not usually a perfectly regular arrangement, and not necessarily the absolute optimum one (and I believe there isn’t any known (non brute-force) way of finding a guaranteed optimum for this sort of problem).

If your boundary volume is reasonably smooth, and large relative to the size of the spheres, the volume fraction based approximation of the number of spheres should be fairly close though.

3 Likes

Thanks for the good feedback.
I understand the math better now (thanks Ethan!)
I still want to make a 3D GH sphere pack calculator.
and doesnt have to be super exact, just a good approximation.
i found few topics but not a solution way yet:

https://www.grasshopper3d.com/forum/topics/geometry-packing-sphere-packing

Sphere Packingspheremeshtest.gh (17.3 KB)

I dont know blender, but GH does physics too.

im just not sure how to change this into a full packed volume with a number count.

This is an idea using voronoi if there is a way to create spheres inside the cells

1 Like

For a rough approximation you can use the volume fraction approach Ethan gives above. The actual number of spheres would generally be less than predicted by this though, depending on their size relative to the volume, its shape, and how they are physically put in there

are these ball-bearings pouring into a hopper, oranges being carefully placed by hand…?

For a physics approach you can try this:
FillVolumeWithSpheres.gh (22.4 KB)
It uses a script which will ask for a reference assembly location, and you need to set the location of your KangarooSolver dll, which is generally
C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Components
There’s a slider for the number of spheres, which you can gradually increase, and their colour is an indication of the pressure, or how much they are overlapping. So if you slowly slide up the number until they are no longer all green, you can see how many fit.
You could also optionally add a Grab component to let you give them a stir if needed to see if they can rearrange to a denser arrangement.
It would also be possible with a bit more work to script the adding of spheres, so it would automatically add them until it was full.

5 Likes

If, as Daniel stated, my previous method overstates the number of spheres, here’s a solution which will slightly understate it. Since the CCP packing has four spheres per unit cell, if you divide the cell into eight subcells, each one will contain 1/2 sphere. The ideas is to create a lattice of one eighth cells (or their centers more accurately) and then check to see how many are contained in your shape. Take the total number contained, and multiply by 1/2. Before, I got 1414 and this method gives 1372.

I hope this isn’t just about winning a jelly bean counting contest.

Spheres in shape.gh (13.2 KB)

2 Likes

This idea need a scripting maybe ; create network from points where the distance between points is fixed x or >x and the spheres radius is x/2

Tnx,
I think i can figure out thr Kangeroo2 version (i already haveit but maybe the wrong version)
but what is the multiplication ? ? ? im missing and betweeen what is it connected ?

Which Rhino version and service release are you using?

image

image

image

Hi Daniel, I’m struggling to use this with different spheres radius, Can i get some help? thanks

Hi @danilo.gigantelli
You could try this:

Oh I tried with this, but the problem is that i have to fill a closed mesh

The same approach works for closed meshes.
Here’s a slightly modified version of that definition:
spherefill.gh (93.8 KB)