0
$\begingroup$

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 ?

$\endgroup$
2
  • $\begingroup$ Do you want to Rotate reg2? $\endgroup$
    – Alan
    Commented Apr 20, 2023 at 14:14
  • 1
    $\begingroup$ 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. $\endgroup$
    – Syed
    Commented Apr 21, 2023 at 4:13

2 Answers 2

0
$\begingroup$

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]

enter image description here

$\endgroup$
1
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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