5
$\begingroup$

How can one define and render in 3D a single solid object using logical operations on component solid objects? For instance, I would like to define a solid object that consists of a Cuboid punctured by a Cylinder between two opposite faces, i.e., with a hole through it. Alternatively, I would like to define a single solid object that consists of a Cuboid with a face-matched Tetrahedron extending from it. Ideally, the volume, number of faces, and such for these more complicated solid objects would be determined automatically.

I don't believe GraphicsGroup will work because one cannot remove one solid object from another, as needed in the Cuboid and Cylinder example. Moreover, RegionIntersection does not work appropriately with volumes in 3D.

Of course one could use RegionPlot3D and write lots of constraint equations, but this is complicated and requires a large number of PlotPoints for adequate rendering. Moreover, there would be no natural way to count the object's faces. A method based on the data returned by PolyhedronData would be ideal.

$\endgroup$
  • $\begingroup$ reference.wolfram.com/language/ref/BoundaryMeshRegion.html? Check the example cuboids with voids. $\endgroup$ – alancalvitti Oct 24 '14 at 4:39
  • $\begingroup$ ` BooleanRegion, RegionUnion, RegionIntersection`, etc. will not work with mesh or boundary mesh regions in 3D. They will work with implicit regions, parametric regions, and their mixes. $\endgroup$ – DavidC Oct 25 '14 at 18:03
7
$\begingroup$

Use the Region functions in version 10


Update: Cube punctured by cylinder

Let's tackle the first issue, the cube punctured by the cylinder. It's a matter of subtracting their regions.

(*Find the region of the solid cube *)
R5 = Cuboid[];
CubeRegion = ImplicitRegion[RegionMember[R5, {x, y, z}], {x, y, z}]
cubePlot = 
  RegionPlot3D[CubeRegion, PlotPoints -> 40, Axes -> True, 
   ImageSize -> 450];

(*Find the region of the cylinder *)    
R0 = Cylinder[{{1/2, 1/2, 0}, {1/2, 1/2, 1}}, 1/4];
CylinderRegion = ImplicitRegion[RegionMember[R0, {x, y, z}], {x, y, z}]
cylinderPlot = 
  RegionPlot3D[CylinderRegion, PlotPoints -> 40, Axes -> True];


(*find their difference *)

differencePlot = 
  RegionPlot3D[RegionDifference[CubeRegion, CylinderRegion], 
   PlotPoints -> 40, Axes -> True, ImageSize -> 450];

(*show all 3 plots *)
GraphicsGrid[{{cylinderPlot, cubePlot, differencePlot}}, 
 ImageSize -> 700]

The implicit regions below correspond to the solid cube and cylinder.

BooleanRegion might also be used to find the difference region.

cube


First Draft: Cube and Tetrahedron

I'm including my earlier response, despite the fact that it was quickly thrown together, because it gives some ideas about how to apply logical operations to regions defined in GraphicsData.

The approach that uses ImplicitRegion and RegionUnion RegionUnion logically joins the objects.


I thought a the objects would both be hollow since the data are from PolyhedronData[] but RegionFunction returns filled regions (i.e solid objects). And that is what the OP is looking for.

Here is the region function for the cube. The center of the cube is at the origin.

PolyhedronData["Cube", "RegionFunction"][x, y, z]

2 z <= 1 && 2 x <= 1 && 2 y <= 1 && x >= -(1/2) && z >= -(1/2) && y >= -(1/2)


I shifted the cube 1/2 unit downward to offset it from the pyramid (filled tetrahedron with center at the origin.) This shift is achieved by adding 1/2 to the z:

PolyhedronData["Cube", "RegionFunction"][x, y, z+1/2]

2 (1/2 + z) <= 1 && 2 x <= 1 && 2 y <= 1 && x >= -(1/2) && 1/2 + z >= -(1/2) && y >= -(1/2)

I was sloppy about the positioning of objects. Some experimentation would be needed to apply transformations to the objects.


RegionUnion

R1 =ImplicitRegion[PolyhedronData["Cube", "RegionFunction"][x, y, z + 1/2], {x, y,z}]
R2 =ImplicitRegion[PolyhedronData["Tetrahedron", "RegionFunction"][x, y, z], {x, y,z}]
RegionPlot3D[RegionUnion[R1, R2], PlotPoints -> 100, Axes -> True, AxesLabel -> {"x", "y", "z"}]

region1


RegionDifference 1

We can subtract the tetrahedron region from the cube region. Both the tetrahedron and the cube are treated as filled objects.

RegionPlot3D[RegionDifference[R1, R2], PlotPoints -> 100, Axes -> True, AxesLabel -> {"x", "y", "z"}]

region2


RegionDifference 2

This subtracts the cube region from the tetrahedron region.

RegionPlot3D[RegionDifference[R2, R1], PlotPoints -> 100, Axes -> True, AxesLabel -> {"x", "y", "z"}]

region3


RegionIntersection

RegionPlot3D[RegionIntersection[R2, R1], PlotPoints -> 100, Axes -> True, AxesLabel -> {"x", "y", "z"}]

region4

$\endgroup$
  • $\begingroup$ A useful reference: reference.wolfram.com/language/guide/DerivedRegions.html $\endgroup$ – DavidC Oct 24 '14 at 12:37
  • $\begingroup$ It would be great to create a Platonic tetrahedron with four edge-aligned triangular prisms piercing the tetrahedron, one through each vertex and the center of its opposite face. This would allow us to visual the total number of faces of this complex solid. $\endgroup$ – David G. Stork Oct 27 '14 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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