# How to graph a solid common to multiple functions

I want to be able to graph the solid that is contained by two functions. I am graphing x^2+z^2=400 and y^2+z^2=400 and this the code I used and the graph I got:

    Plot3D[{z = Sqrt[400 - x^2], z = Sqrt[400 - y^2], z = -Sqrt[400 - x^2],
z = -Sqrt[400 - y^2]}, {x, -50, 50}, {y, -50, 50}]


I was wondering how I could graph the solid common to the cylinders aka the solid that the cylinders form.

CSGRegion["Intersection", {Cylinder[{{0, -20, 0}, {0, 20, 0}}, 20],
Cylinder[{{-20, 0, 0}, {20, 0, 0}}, 20]}, BaseStyle -> Darker@Cyan]


Edit

Use OpenCascadeLink  as highlighted by @user21:

Needs["OpenCascadeLink"];
Needs["NDSolveFEM"];
reg1 = ImplicitRegion[x^2 + z^2 <= 400, {x, y, z}];
reg2 = ImplicitRegion[y^2 + z^2 <= 400, {x, y, z}];
ToBoundaryMesh[reg1, {{-20, 20}, {-20, 20}, {-20, 20}},
MaxCellMeasure -> 1]];
ToBoundaryMesh[reg2, {{-20, 20}, {-20, 20}, {-20, 20}},
MaxCellMeasure -> 1]];
"ShapeSurfaceMeshOptions" -> {"AngularDeflection" -> .1}] //
BoundaryMeshRegion;
bm // Volume
RegionPlot3D[bm, ColorFunction -> "Rainbow", Boxed -> False]


• Wonderful stuff as usually. Just saw the edited version. Would it be possible to include a link to the original answer by user21? It's very good and I'd like to give an upvote to that as well :)
– bmf
Apr 25, 2022 at 4:02
• @bmf We can find another examples in user21's package "OpenCascadeLink". reference.wolfram.com/language/OpenCascadeLink/tutorial/… Apr 25, 2022 at 4:19
• oh cool. that's what you meant. thanks for the link :)
– bmf
Apr 25, 2022 at 4:21
• Add an answer here for completeness?: mathematica.stackexchange.com/questions/211178/… Jun 12, 2022 at 7:41
• @xzczd OK, Thanks. Jun 12, 2022 at 11:13
DiscretizeRegion[
ImplicitRegion[-Sqrt[400 - x^2] <= z <=
Sqrt[400 - x^2] && -Sqrt[400 - y^2] <= z <= Sqrt[400 - y^2], {x,
y, z}], MaxCellMeasure -> 1,
BaseStyle -> Directive[Specularity[White, 50], Opacity[0.8], Orange]]


To begin with, I think the following is more natural for the full plot

ContourPlot3D[{x^2 + z^2 - 400, y^2 + z^2 - 400}, {x, -50,
50}, {y, -50, 50}, {z, -50, 50},
ContourStyle -> {Opacity[1], Opacity[1]}]


And we can dissect different parts of it

one = RegionPlot3D[{x^2 + z^2 - 400 >= 0 &&
y^2 + z^2 - 400 >= 0}, {x, -50, 50}, {y, -50, 50}, {z, -50, 50},
Mesh -> None]


two = RegionPlot3D[{x^2 + z^2 - 400 >= 0 &&
y^2 + z^2 - 400 <= 0}, {x, -50, 50}, {y, -50, 50}, {z, -50, 50},
Mesh -> None, PlotPoints -> 75]


three = RegionPlot3D[{x^2 + z^2 - 400 <= 0 &&
y^2 + z^2 - 400 >= 0}, {x, -50, 50}, {y, -50, 50}, {z, -50, 50},
Mesh -> None, PlotPoints -> 75]


And finally

four = RegionPlot3D[{x^2 + z^2 - 400 <= 0 &&
y^2 + z^2 - 400 <= 0}, {x, -50, 50}, {y, -50, 50}, {z, -50, 50},
Mesh -> None, PlotPoints -> 75]


You can use Show to combine the different bits

Show[three, four]


Using CSG functionality introduced in 13.0

CSGRegion["Union",
{Cylinder[{{-50, 0, 0}, {50, 0, 0}}, 20],
Cylinder[{{0, -50, 0}, {0, 50, 0}}, 20]}]


CSGRegion["Intersection",
{Cylinder[{{-50, 0, 0}, {50, 0, 0}}, 20],
Cylinder[{{0, -50, 0}, {0, 50, 0}}, 20]}]


reg = BoundaryDiscretizeGraphics@Plot[{-Cos[x], Cos[x]}, {x, 0, 2 Pi}, Filling -> 0]

ParametricPlot3D[20 {{Cos[t], h, Sin[t]}, {h, Cos[t], Sin[t]}} // Evaluate,
Element[{t, h}, reg]] // AbsoluteTiming


or

 ParametricPlot3D[
20 {{Cos[t], u Cos[t], Sin[t]}, {u Cos[t], Cos[t], Sin[t]}}//Evaluate,
{t, 0, 2 Pi}, {u, -1, 1}, Mesh -> None, PlotPoints -> 100, MaxRecursion -> 3]