Boolean operations for 3D objects
Let's split the components:
reg = {Cylinder[{orig, {comp, 0, 0}}, r1],
Cylinder[{{altRasgo/2, 0, -r1}, {altRasgo/2, 0, r1}}, r2],
Cuboid[{0, -r1, -7.5}, {30, r1, 7.5}]};
and use RegionDifference
twice:
rr = RegionDifference[RegionDifference[reg[[1]], reg[[2]]], reg[[3]]];
Then you can
RegionPlot3D[rr, PlotPoints -> 100]
Directly with regions:
comp = 200;
altRasgo = 30;
r1 = 25;
r2 = 7.5;
region1 = (comp > x > 0 && y^2 + z^2 < r1^2);
region2 = (((x - altRasgo/2)^2 + y^2) < r2^2 && r1 > z > -r1);
region3 = (0 < x < 30 && -r1 < y < r1 && -7.5 < z < 7.5);
RegionPlot3D[
region1 && ! region2 && ! region3, {x, 0, comp}, {y, -comp/2,
comp/2}, {z, -comp/2, comp/2}, Mesh -> None, PlotPoints -> 50,
PlotStyle -> Darker[Gray]]
Generation higher quality model:
r = DiscretizeRegion[
ImplicitRegion[
region, {x, y, z}], {{0, comp}, {-comp/2, comp/2}, {-comp/2,
comp/2}}, Method -> "RegionPlot3D", MaxCellMeasure -> 10];
rr = GraphicsComplex[MeshCoordinates@#, MeshCells[#, 2]] &@r;
Graphics3D[{EdgeForm[], Darker[Gray], rr}, Lighting -> "Neutral",
Boxed -> False]
With the new in version 12.1 OpenCascadeLink you get very crisp corners:
Needs["OpenCascadeLink`"]
Needs["NDSolve`FEM`"]
(*Corpo Principal*)
orig = {0, 0, 0};
diam1 = 50;
r1 = diam1/2;
comp = 200;
(*Furo*)
diam2 = 15;
r2 = diam2/2;
(*Rasgo*)
altRasgo = 30;
largRasgo = 15;
reg = {Cylinder[{orig, {comp, 0, 0}}, r1],
Cylinder[{{altRasgo/2, 0, -r1}, {altRasgo/2, 0, r1}}, r2],
Cuboid[{0, -r1, -7.5}, {30, r1, 7.5}]}; rr =
RegionDifference[RegionDifference[reg[[1]], reg[[2]]], reg[[3]]];
ocr = OpenCascadeShapeBooleanRegion[rr];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[ocr,
"ShapeSurfaceMeshOptions" -> {"LinearDeflection" -> 0.5}];
groups = bmesh["BoundaryElementMarkerUnion"];
temp = Most[Range[0, 1, 1/(Length[groups])]];
colors = ColorData["BrightBands"][#] & /@ temp;
bmesh["Wireframe"["MeshElementStyle" -> FaceForm /@ colors]]