yanglin5
(yang l)
January 28, 2015, 9:00am
1
My question is that: how to make a hole in a Graphics3D object? For example, there are two objects ,cub1 and cub2:
cub1=Cuboid[{0,0,0},{20,2,20}];
cub2=Cuboid[{12,0,8},{17,2,17}];
Graphics3D[{cub1,cub2}]
I want to make a window at the positon of the cub2, like under.
DiscretizeRegion[RegionDifference[cub1,cub2]]
But this object is obtained by use DiscretizeRegion, it is not a Graphics3D object, it is a MeshRegion object, and it make system too slow. Then, how to get a Graphics3D object?
Vitaliyk
(Vitaliy Kaurov)
January 28, 2015, 2:02pm
2
Let’s start from your code:
cub1 = Cuboid[{0, 0, 0}, {20, 2, 20}];
cub2 = Cuboid[{12, 0, 8}, {17, 2, 17}];
Graphics3D[{cub1, cub2}];
reg = DiscretizeRegion[RegionDifference[cub1, cub2]]
You have a lot of tetrahedrons:
MeshCells[reg, 3] // Length
10093
And a lot of polygons:
MeshCells[reg, 2] // Length
22096
You do not need all that for visual, - so get the surface (boundary):
surface = BoundaryDiscretizeRegion[reg];
polygons = MeshCells[surface, 2];
polygons // Length
3820
Now so few polygons! Get the coordinates of the mesh too:
points = MeshCoordinates[surface];
points // Length
> 1910
And here you go:
Graphics3D[{EdgeForm[Gray],
GraphicsComplex[points, Polygon[polygons /. Polygon[x_] -> x]]},
Boxed -> False, Lighting -> "Neutral"]
nma
(Nasser M. Abbasi)
January 28, 2015, 2:29pm
3
another option (made the cube little thicker to make it more clear ) there are many more options in the RegionPlot3D you can adjust also.
cub1 = Cuboid[{0, 0, 0}, {20, 6, 20}];
cub2 = Cuboid[{12, 0, 8}, {17, 6, 17}];
r2 = RegionDifference[cub1, cub2];
RegionPlot3D[r2, PlotPoints -> 60, Mesh -> 10]
Vitaliyk
(Vitaliy Kaurov)
January 28, 2015, 2:31pm
4
Wow, Nasser, such a nice compact solution!
charlesp
(Charles Pooh)
January 28, 2015, 5:45pm
5
You can also apply Show to the mesh region. Show will preserve the styling and meshing.
yanglin5
(yang l)
January 29, 2015, 9:58am
6
Thanks, it is a good solution. Wolfram should support Boolean operation for Graphics3D objects in future.