copy the link of the current played video/stream in iOS
When working with regions, you can either work with exact Region
primitives, or discretized versions of the Region
primitives. For example, a Cylinder
object is an exact Region
primitive, while using DiscretizeRegion
on such an object produces the discretized version.
In general, using exact Region
primitives inside of functions like RegionDifference
is more difficult than using the discretized versions. With exact primitives, the output can't always be reduced to a single primitive, and so you're left with a BooleanRegion
object. With the discretized versions, the output can always be reduced to a single discretized object. I recommend working with discretized versions.
Now, there were two issues with your first example. When working with inexact numbers, sometimes Mathematica is unable to determine whether the region is a valid region or is degenerate in some way. So:
DiscretizeRegion @ Hexahedron[hexpts]
DiscretizeRegion::regpnd: A non-degenerate region is expected at position 1 of DiscretizeRegion[Hexahedron[{{1.7,1.5,0},{1.7,10.8,0},{20.3,10.8,0},{20.3,1.5,0},{1.7,1.5,0.6},{1.7,10.8,0.6},{20.3,10.8,0.6},{20.3,1.5,0.6}}]].
DiscretizeRegion[ Hexahedron[{{1.7, 1.5, 0}, {1.7, 10.8, 0}, {20.3, 10.8, 0}, {20.3, 1.5, 0}, {1.7, 1.5, 0.6}, {1.7, 10.8, 0.6}, {20.3, 10.8, 0.6}, {20.3, 1.5, 0.6}}]]
Notice that DiscretizeRegion
thinks that the Hexahedron
object is degenerate. Your workaround was to use Round
and scaling. It is much simpler to just rationalize the points:
DiscretizeRegion @ Hexahedron[Rationalize[hexpts, 0]]
(the other issue was minor. It is simpler to avoid using the Region
wrapper, as it is mostly a wrapper that displays regions. So, use RegionDifference[Hexahedron[.], Cylinder[.]]
instead of RegionDifference[Region @ Hexahedron[.], Region @ Cylinder[.]]
).
All of your other examples will work fine with this approach. For instance, your last example (I fixed a typo where I think pts4
should have been used instead of pts3
):
pts1 = Rationalize[{{1.7276, 1.47295, -0.01}, {1.7276, 10.77705, -0.01}, {20.2724,
10.77705, -0.01}, {20.2724, 1.47295, -0.01}, {1.7276, 1.47295,
0.6}, {1.7276, 10.77705, 0.6}, {20.2724, 10.77705, 0.6}, {20.2724,
1.47295, 0.6}},0];
pts2 = Rationalize[{{1.7276, 1.47295, 0.6}, {1.7276, 10.77705, 0.6}, {20.2724,
10.77705, 0.6}, {20.2724, 1.47295, 0.6}, {2.5802, 2.09795,
1.85}, {2.5802, 10.15205, 1.85}, {19.2235, 10.15205,
1.85}, {19.2235, 2.09795, 1.85}},0];
pts3 = Rationalize[{{1.7276, 0.47295, 0.6}, {1.7276, 11.77705, 0.6}}, 0];
pts4 = Rationalize[{{14.2533, 0.47295, 0.6}, {14.2533, 11.77705, 0.6}}, 0];
{cr1, cr2} = {2.25, 1.5};
reg1 = DiscretizeRegion[Hexahedron @ pts1];
reg2 = DiscretizeRegion[Hexahedron @ pts2];
reg3 = DiscretizeRegion[Cylinder[pts3, cr1]];
reg4 = DiscretizeRegion[Cylinder[pts4, cr2]];
reg5 = RegionDifference[
RegionUnion[reg1, reg2],
RegionUnion[reg3, reg4]
]