I'm trying to take the difference between two regions. In this case, one region is a cuboid, and the other is a cylinder. Here's what they look like drawn with Graphics3D:
hCub = 1.5;
W = 5;
L = 5;
cub = Cuboid[{0, 0, 0}, {W, L, hCub}];
cyl2botpt = {W, .5*L, 0};
cyl2toppt = {W, .5*L, hCub};
cyl2 = Cylinder[{cyl2botpt, cyl2toppt}, W/15];
Graphics3D[{Lighting -> "Neutral", Gray, Opacity[.5], cub, Opacity[1],
White, cyl2}, Boxed -> False, ImageSize -> 800]
Now what I'd really like to do is, subtract the cylinder region from the cuboid (so that what remains is the cuboid with half a cylinder sized volume missing from its side; I want the other side of the cylinder gone as well). More specifically, I'd like the part that was subtracted from the cuboid to have its surface be white, while the rest of the cuboid surface remains gray.
To attempt this, I tried using RegionDifference. However, that's not a graphics primitive anymore, so you can't use it with Graphics3D, you apparently have to use RegionPlot3D; in fact, it seems like you can't even stick it directly in there (I tried and it threw an error), because you have to use DiscretizeRegion on it first:
regdiff =
DiscretizeRegion[RegionDifference[cub, cyl2], AccuracyGoal -> 12];
RegionPlot3D[regdiff, PlotStyle -> Directive[Opacity[.4]],
BoundaryStyle -> Black, Boxed -> False]
However, this looks pretty bad. If you look at the edges, they're nowhere as clean as they were in the Graphics3D version:
I tried cranking the AccuracyGoal up in the code above, hoping that it would make a more accurate region, but for whatever reason it didn't appear to.
I also tried discretizing the cuboid and cylinder separately before taking their difference, but that didn't seem to help either.
Additionally, I'd have no clue how to do the coloring thing I'd like to achieve that I mentioned before.
So my question has two components: 1) Is this the best way to create this shape, or is there a clever way to do it with Graphics3D? Graphics3D seems "cleaner" but obviously you need primitives, and I don't know how to do it that way. And 2), how can I do the different boundary coloring that I mentioned?
PlotPoints
. If anyone disagrees with this and prefers a different original please comment. $\endgroup$