I would like to know how to calculate the volume of the union of multiple possibly intersecting spheres (using Sphere[]). Please see the figure:

I was trying to get a mesh/delaunayMesh out of the spheres and apply "Volume" which didn't work.
Edit: Fixed spelling (Feb 6th).
Answer
spheres = {
Sphere[{50, 50, 50}, 25],
Sphere[{70, 70, 70}, 25]};
rgn = RegionUnion @@
(spheres /. Sphere -> Ball);
RegionMeasure[rgn // N]
122585.
Volume[rgn // N]
122585.
EDIT: Example with more elements
rgn2 = RegionUnion[
Ball[{100., 100., 100.}, 30.], Ball[{120., 120., 120.}, 30.],
Ball[{130., 130., 130.}, 30.], Ball[{140., 140., 140.}, 30.],
Ball[{190., 190., 190.}, 30.], Ball[{200., 200., 200.}, 30.],
Ball[{210., 210., 210.}, 30.], Ball[{230., 230., 230.}, 30.]];
RegionMeasure[rgn2]
590768.
Volume[rgn2]
590768.
Comments
Post a Comment