# Material removal in a geometric shape

I want to do the same as in this program but drilling the rectangle in another direction, along an axis other than that of the cylinder :

plot = Disk[{0, 0}, 3]
mesh = DiscretizeGraphics@plot;
reg = RegionProduct[mesh, Line[{{0}, {N[6]}}]];

plot2 = Rectangle[{-1, -2}]
mesh2 = DiscretizeGraphics@plot2;
reg2 = RegionProduct[mesh2, Line[{{3}, {N[8]}}]];

rd = RegionDifference[reg, reg2];

Graphics3D[{EdgeForm[], Lighter[RGBColor["#2980b9"]], rd},
Lighting -> "Neutral", Axes -> True]


How to do ?

• Do you want to Rotate reg2?
– Alan
Commented Apr 20, 2023 at 14:14
• Welcome to the Mathematica Stack Exchange. If you have started learning Mathematica, then you will find that the introductory book written by the inventor is a good learning resource. Also, do not forget to upvote the answer(s) you like and accept the most suitable answer by clicking on the checkmark right next to that answer. Thanks.
– Syed
Commented Apr 21, 2023 at 4:13

You can create the piece to subtract in an arbitrary direction, e.g.:

plot2 = Rectangle[{-1, -2}]
mesh2 = DiscretizeGraphics@plot2;


Then you can rotate and translate the object as needed by defining a transformation function "transform" and transfrom the object accordingly:

transform =  Composition[TranslationTransform[{0, 0, 2}], RotationTransform[  Pi/2, {0, 1, 0}]];
reg2 = GeometricTransformation[ RegionProduct[mesh2, Line[{{-8}, {8.}}]], transform ];


Then we can create the subtraction and plot the result:

rd = RegionDifference[reg, reg2];
Graphics3D[{EdgeForm[], Lighter[RGBColor["#2980b9"]], rd},
Lighting -> "Neutral", Axes -> True]


You could also experiment with CSGRegion

CSGRegion["Difference",
{Cylinder[{{0, 0, 0}, {0, 0, 6}}, 2],
Cuboid[{-1, -1, 2}, {-2, -2, 3}]},
Axes -> True,
AspectRatio -> 1]