# Boolean operation to obtain volume

Imagine a sphere with $R40$ centered at ${0,0,0}$.

Now a cylinder with $R25$ tangent in one of the quadrants of the sphere ending on the surface of the sphere.

How do I get the volume of the resulting solid?

r1 = 40; r2 = 25;
Graphics[{ Circle[{0, 0}, r1], Line[{{r1, r2}, {r1, -r2}}], Line[{{Sqrt[r1^2 - r2^2], r2}, {r1, r2}}], Line[{{Sqrt[r1^2 - r2^2], -r2}, {r1, -r2}}] }]


## 2 Answers

r1 = 40; r2 = 25;
R = RegionUnion[Ball[{0, 0, 0}, r1],
Cylinder[{{Sqrt[r1^2 - r2^2], 0, 0}, {r1, 0, 0}}, r2]];
R // Volume


250/3 (812 + 39 Sqrt[39]) π

Graphics3D[{{Opacity[0.5], Red, Ball[{0, 0, 0}, r1]}, {Opacity[0.5],
Blue, Cylinder[{{Sqrt[r1^2 - r2^2], 0, 0}, {r1, 0, 0}}, r2]}}]


Volume of the blue solid:

Volume[R] - Volume[Ball[{0, 0, 0}, r1]]


-(53000 π/3) + 3250 Sqrt[39] π

using RegionIntersection also returns the same result:

R = RegionIntersection[Ball[{0, 0, 0}, r1],
Cylinder[{{Sqrt[r1^2 - r2^2], 0, 0}, {r1, 0, 0}}, r2]];
Volume[Cylinder[{{Sqrt[r1^2 - r2^2], 0, 0}, {r1, 0, 0}}, r2]] - Volume[R]

• Could you add the information on the volume of the blue solid? I know it would subtract the volume from the sphere, but there may be a more effective method. Commented May 17, 2017 at 13:20
• @LCarvalho I think subtracting the sphere volume is the best method because we have that result already calculated. Another method can be to subtract intersection volume of the solids from the volume of cylinder. Commented May 17, 2017 at 14:03
r1 = 40; r2 = 25;

rgns = {Ball[{0, 0, 0}, r1],
Cylinder[{{Sqrt[r1^2 - r2^2], 0, 0}, {r1, 0, 0}}, r2]};


Ball and Cylinder are regions

RegionQ /@ rgns

(*  {True, True}  *)

Volume[RegionUnion @@ rgns] // FullSimplify

(*  250/3 (812 + 39 Sqrt[39]) π  *)


Verifying with alternate approaches

Total[Volume /@ rgns] - Volume[RegionIntersection @@ rgns] // Simplify

(*  250/3 (812 + 39 Sqrt[39]) π  *)

Integrate[1, {x, y, z} ∈ (RegionUnion @@ rgns)] // FullSimplify

(*  250/3 (812 + 39 Sqrt[39]) π  *)

Graphics3D[rgns]