
While we’re at it, modifying the circle packing script to do sphere packing is (un)surprisingly simple. It uses the same logic as the 2D circle packing script just applied to 3 dimensions. Obviously there are many different packing algorithms which yield different packing efficiencies. This one is surely not the most effiencent packing algorithm but it is quite fast.


Download:
spherePacking3D_v1.ghx – Grasshopper versions prior to 0.7
spherePacking3D_v1.1.ghx – Grasshopper 0.8.0004
hi.
this is a nice little script. seems very efficient.
is there a way that it could be modified to have a boundary defined by existing geometry or other geometry created by grasshopper?
thanks and nice work.
carter
In 2 dimensions, you could use an arbitrary closed curve as boundary and check if a center point is inside that boundary. If not, choose another random center point, if yes, then define the radius of the circle by determining the distance to the closest circle or alternatively to the closest point on the curve whichever is closer. That logic should also work in 3D with arbitrary closed volumes. Let me know what you think.
Hi there, thanks for the script. I was working on exactly the same problem. But it seems like there is an error running your script. I loaded in Grasshopper and no results are shown. Is there any initial settings I need to make before I launch it?
Great work btw,
Hi, Thanks for letting me know. What is very likely happening is that the version of GH that I used at the time to create this definition is not fully compatible with the current version of GH. I should probably just update the definition to work with RhinoCommon instead of the old SDK. But still, I’m wondering what error message are you getting and which version of GH are you using. Let me know and I’ll fix it. Best, Tobias.
Dear Tobias,
Thanks for your reply. I am using the latest GH just released from their website. I guess it might be the compatibility issue. How do I post an image here? I have a screenshot of the error msgs.
Otherwise, here is what it says:
Error: Name ‘Abs’ is not declared. (line 114)
Error: Name ‘Abs’ is not declared. (line 117)
Error: Name ‘Abs’ is not declared. (line 120)
Error: Name ‘Abs’ is not declared. (line 123)
Error: Name ‘Abs’ is not declared. (line 126)
Error: Name ‘Abs’ is not declared. (line 129)
Let me know if you get it fixed. I am very excited to see the file!
Best,
Fan
Hi, I fixed it and posted a link to the updated file above.
Best,
Tobias
thanks Tobias, the script is running smoothly now!
One more question, are the min and max radii of the spheres?
The min and the max values are defining the extents of the bounding box within which the spheres are generated. Of course, there can be different ways to define the space where the packing occurs. Best, Tobias
Hi, do you have this code written in C#? Thanks