5
|
16804 Views
|
5 Replies
|
16 Total Likes
View groups...
Share
GROUPS:

# How to make a hole in a Graphics3D object?

Posted 9 years ago
 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?
5 Replies
Sort By:
Posted 9 years ago
 You can also apply Show to the mesh region. Show will preserve the styling and meshing.
Posted 9 years ago
 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] Posted 9 years ago
 Wow, Nasser, such a nice compact solution!
Posted 9 years ago
 Thanks, it is a good solution. Wolfram should support Boolean operation for Graphics3D objects in future.
Posted 9 years ago
 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"] 