3 or more Sphere intersection


I’m trying to write a script which basically create a 4 (or potentially 5th) sphere following a certain procedure. I know that there may be easier ways, plus given that my spheres are created in grasshopper, however given that its been a few weeks since I got myself into python scripting I had to do with the amount of knowledge I acquired so far.
The method I am trying to recreate is basically offsetting the 3 or 4 spheres, then find the intersection between the offsets, the distance of offset being equal to the radius of the new sphere. I have meshes and well untrimmed surfacesaka spheres surfaces as grasshopper creates them.

I tried out the surface bit, but since the sphereintersection requires the planes which would be difficult for me to get them in rhino. I even tried the brep brep intersection ,which didn’t end with any results.

Passing onto meshes, it either doesn’t do anything, or it offsets the spheres on the inside as opposed to the outside.

Can anybody tell me where am I screwing up ? :slight_smile:

SpherePack3D.py (1.2 KB)
Points within surface.gh (71.3 KB)

You might probably know this already, but your stated problem has a simple geometric construction that does not rely on meshes at all:

In pseudocode:

intersect(sphere1, sphere2) => circle1
circle1.getplane() => plane1
intersect(plane1, sphere3) => circle2
intersect(circle1, circle2) => (point1, point2)

# select one of the points 
# construct sphere around the point with radius = offset

If you are having trouble with the implementation, maybe rhinoscriptsyntax doesn’t have good support for spheres, and you have to use RhinoCommon methods such as


Reference docs:

thia was my plan, as it is how I did it in rhino, intersecting 2 spheres, then intersect the 3rd spheres withe the intersection curve. But since I struggled to intersect 2 spheres, started trying out stuff, and got lost :smiley: