7
$\begingroup$

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}]

enter image description here

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

$\endgroup$
3

5 Answers 5

18
$\begingroup$

Related https://mathematica.stackexchange.com/a/269363/72111

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

3d rendering of union region

Edit

Use OpenCascadeLink` as highlighted by @user21:

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

enter image description here

$\endgroup$
5
  • $\begingroup$ 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 :) $\endgroup$
    – bmf
    Commented Apr 25, 2022 at 4:02
  • 2
    $\begingroup$ @bmf We can find another examples in user21's package "OpenCascadeLink". reference.wolfram.com/language/OpenCascadeLink/tutorial/… $\endgroup$
    – cvgmt
    Commented Apr 25, 2022 at 4:19
  • $\begingroup$ oh cool. that's what you meant. thanks for the link :) $\endgroup$
    – bmf
    Commented Apr 25, 2022 at 4:21
  • $\begingroup$ Add an answer here for completeness?: mathematica.stackexchange.com/questions/211178/… $\endgroup$
    – xzczd
    Commented Jun 12, 2022 at 7:41
  • $\begingroup$ @xzczd OK, Thanks. $\endgroup$
    – cvgmt
    Commented Jun 12, 2022 at 11:13
10
$\begingroup$
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]]

enter image description here

$\endgroup$
6
$\begingroup$

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]}]

plot1

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]

plot2

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]

plot3

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]

plot4

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]

plot5

You can use Show to combine the different bits

Show[three, four] 

show

$\endgroup$
5
$\begingroup$

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]}]

enter image description here

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

enter image description here

$\endgroup$
0
3
$\begingroup$
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

enter image description here

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.