How To Draw 3D Regions?
How To Draw 3D Regions?
I want to draw some non-trivial Region. Region[ℛ, ...] normally does the job. But for simple regions only.
Then I try RegionPlot3D, but it does not succeed. Can someone help me?
Then I try RegionPlot3D, but it does not succeed. Can someone help me?
In[]:=
ClearAll["Global`*"]
An example
An example
A rail support workpiece from the WL-documentation to CSGRegion, CAD Modeling. This example works with CSGRegion but not with Region.
PlotRange and options:
In[]:=
pr={{-26,26},{-10,10},{0,40}}prp=2options=Sequence@@{PlotRange->pr,PlotRangePadding->prp,Boxed->True,Axes->True,AxesStyle->Darker[Gray,0.9],AxesLabel->(Style[#,Bold,12]&/@{"x","y","z"}),ImageSize->300}
Out[]=
{{-26,26},{-10,10},{0,40}}
Out[]=
2
Out[]=
Sequence[PlotRange{{-26,26},{-10,10},{0,40}},PlotRangePadding2,BoxedTrue,AxesTrue,AxesStyle,AxesLabel{x,y,z},ImageSize300]
Construct with Region operations
Construct with Region operations
The RegionUnion, RegionDifference, RegionsIntersection, etc. region operations usually generate BooleanRegion expressions or, if they are simple shapes, Graphics primitives directly. Therefore, in general, they cannot be rendered directly with Graphics3D. But with Region or some kind of RegionPlot3D.
In[]:=
(*WorkpiecepartCubes*)(*---TheGraphics3Dprimitives*)primsCubes={Cuboid[{-10,-10,0},{10,10,40}],Cuboid[{-26,-10,0},{26,10,5}]};(*---TheRegion*)ℛCubes=RegionUnion@@primsCubes(*---Display*)Region[ℛCubes,options]Graphics3D[primsCubes,options]
Out[]=
Polyhedron
Out[]=
Out[]=
In[]:=
(*Workpiecepartholes*)(*---TheGraphics3Dprimitives*)primsHoles={Cuboid[{-1,-12,30},{1,12,50}],Cylinder[{{-20,0,35},{20,0,35}},2],Cylinder[{{0,-20,25},{0,20,25}},7],Cylinder[{{-18,0,-1},{-18,0,12}},4],Cylinder[{{18,0,-1},{18,0,12}},4]};(*---TheRegion*)ℛHoles=RegionUnion@@primsHoles(*---Display*)Region[ℛHoles,options]Graphics3D[primsHoles,options]
Out[]=
BooleanRegion[#1||#2||#3||#4||#5&,{Cuboid[{-1,-12,30},{1,12,50}],Cylinder[{{-20,0,35},{20,0,35}},2],Cylinder[{{0,-20,25},{0,20,25}},7],Cylinder[{{-18,0,-1},{-18,0,12}},4],Cylinder[{{18,0,-1},{18,0,12}},4]}]
Out[]=
Out[]=
In[]:=
(*Puttingitalltogether*)ℛ=RegionDifference[ℛCubes,ℛHoles]Region[ℛ,options]
Out[]=
BooleanRegion#1&&!(#2||#3||#4||#5||#6)&,Polyhedron,Cuboid[{-1,-12,30},{1,12,50}],Cylinder[{{-20,0,35},{20,0,35}},2],Cylinder[{{0,-20,25},{0,20,25}},7],Cylinder[{{-18,0,-1},{-18,0,12}},4],Cylinder[{{18,0,-1},{18,0,12}},4]
Out[]=
Region
Unfortunately this workpiece region ℛ is too complex for being displayed with Region[ℛ, …].
Note: Graphics3D[ℛ, …] is not allowed since ℛ is not a Graphics3D primitive or directive.
Plot with RegionPlot3D
Plot with RegionPlot3D
RegionPlot3D[ℛ, …] or RegionPlot3D[{x,y,z}∈ℛ, {x,…}, {y,…}, {z,…}, …] are not allowed since ℛ must be a Boolean function and not a BooleanRegion. But we can try to convert the BooleanRegion ℛ to a BooleanFunction:
BooleanConvert:
In[]:=
Clear[x,y,z];bfunc=BooleanConvert[pr[[1,1]]<=x<=pr[[1,2]]&&pr[[2,1]]<=y<=pr[[2,2]]&&pr[[3,1]]<=z<=pr[[3,2]]&&{x,y,z}∈ℛ,"BFF"]
Out[]=
BooleanFunction-26≤x≤26,-10≤y≤10,0≤z≤40,{x,y,z}∈BooleanRegion#1&&!(#2||#3||#4||#5||#6)&,Polyhedron,Cuboid[{-1,-12,30},{1,12,50}],Cylinder[{{-20,0,35},{20,0,35}},2],Cylinder[{{0,-20,25},{0,20,25}},7],Cylinder[{{-18,0,-1},{-18,0,12}},4],Cylinder[{{18,0,-1},{18,0,12}},4]
This is strange since RegionPlot3D claims that bfunc is not a BooleanFunction. But it is.
I think this doesn’t work since bfunc is not in implicit form.
RegionConvert:
I try to transform ℛ to implicit form.
This doesn’t change anything.
Community
Community
Werner Geiger, 18.01.2023
Werner Geiger, 18.01.2023
Posted this notebook.