1
$\begingroup$

Suppose I have two regions defined by two hexahedrons (slightly adapted from this question):

hexpts = {{1.7, 1.5, 0}, {1.7, 10.8, 0}, {20.3, 10.8, 0.01}, {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}};
reg = Hexahedron[Rationalize[hexpts]];
hexpts2 = {{1.7, 1.5, 0}, {1.7, 10.8, 0}, {20.3, 10.8, 0.01}, {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}} + 0.1;
reg2 = Hexahedron[Rationalize[hexpts2]];
Region@reg

enter image description here

Now I am interested in the RegionUnion of both:

myreg = RegionUnion[reg, reg2]
Region@myreg 

enter image description here

Then all 3 regions are Regions and also bounded regions:

list = {reg, reg2, myreg};
RegionQ[#] & /@ list
BoundedRegionQ[#] & /@ list

{True, True, True}

{True, True, True}

But I cannot calculate the volume nor other region parameters for the region union:

Volume[#] & /@ list

{103.211, 103.211, Volume[BooleanRegion[#1 || #2 &, {Hexahedron[{{17/10, 3/2, 0}, {17/ 10, 54/5, 0}, {203/10, 54/5, 1/100}, {203/10, 3/2, 0}, {17/10, 3/2, 3/5}, {17/10, 54/5, 3/5}, {203/10, 54/5, 3/5}, {203/10, 3/ 2, 3/5}}], Hexahedron[{{9/5, 8/5, 1/10}, {9/5, 109/10, 1/10}, {102/5, 109/10, 11/100}, {102/5, 8/5, 1/10}, {9/5, 8/5, 7/10}, {9/5, 109/10, 7/10}, {102/5, 109/10, 7/10}, {102/5, 8/5, 7/10}}]}]]}

I tried discretizing the region union but it failed with:

 DiscretizeRegion@myreg

DiscretizeRegion::regpnd: A non-degenerate region is expected at position 1 of DiscretizeRegion[BooleanRegion[#1||#2&,{Hexahedron[{{17/10,3/2,0},{17/10,54/5,0},{203/10,54/5,1/100},{203/10,3/2,0},{17/10,3/2,3/5},{17/10,54/5,3/5},{203/10,54/5,3/5},{203/10,3/2,3/5}}],Hexahedron[{{9/5,8/5,1/10},{9/5,109/10,1/10},{102/5,109/10,11/100},{102/5,8/5,1/10},{9/5,8/5,7/10},{9/5,109/10,7/10},{102/5,109/10,7/10},{102/5,8/5,7/10}}]}]].

An error message that was raised in this question but the proposed solution (using Rationalize) isn't applicable for general Hexahedrons as it seems (note that I changed 0 to 0.01 in hexpts[[3,3]])

How do I properly define the RegionUnion of reg and reg2 so I can use Volume, RegionCentroid etc on it?

$\endgroup$
6
  • 1
    $\begingroup$ It seems that "Volume" together with "RegionUnion" does not work properly. E.g. Volume[RegionUnion[Cube[], Ball[0.5 {1, 1, 1}]]] gives an infinite volume. $\endgroup$ Sep 15, 2020 at 20:29
  • $\begingroup$ This totally unrelated to your question, but how did you get this pdf figure in your question? I've tried and stack exchange won't let me. $\endgroup$
    – Chris
    Sep 15, 2020 at 23:38
  • 1
    $\begingroup$ I think you've found a bug. DiscretizeRegion should work. $\endgroup$
    – m_goldberg
    Sep 16, 2020 at 3:43
  • $\begingroup$ @Chris : I just dragged a file into the browser. $\endgroup$
    – Mr Puh
    Sep 21, 2020 at 12:04
  • $\begingroup$ @m_goldberg : yes, however I changed the regularity of this hexagon a bit compared to the other question. If you change the value 0.01 to 0 DiscretizeRegion works. Any idea why? $\endgroup$
    – Mr Puh
    Sep 21, 2020 at 12:05

1 Answer 1

2
$\begingroup$

Use ConvexHullMesh on the hexahedron points, yields equivalent results.

ps1 = {{1.7, 1.5, 0}, {1.7, 10.8, 0}, {20.3, 10.8, 0.01}, {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}};
ps2 = ps1 + 0.1;
ch1 = ConvexHullMesh@ps1;
ch2 = ConvexHullMesh@ps2;
uch = RegionUnion[ch1, ch2];
RegionCentroid@uch
Volume@uch

{11.0386, 6.19422, 0.350848}

122.174

Hexahedron can be used with RegionUnion and Volume, see example below. So I suspect something might be funky in your point data.

ps0 = {{0, 0, 0}, {1, 0, 0}, {2, 1, 0}, {1, 1, 0}, {0, 0, 1}, {1, 0, 
    1}, {2, 1, 1}, {1, 1, 1}};
ps1 = #*{1.8, 0.9, 0.5} & /@ ps0;
ps2 = #*{1.2, 1.5, 1.8} + 0.3 & /@ ps0;
h1 = Hexahedron@ps1;
h2 = Hexahedron@ps2;
uh = RegionUnion[h1, h2];
RegionCentroid@uh
Volume@uh
Graphics3D@uh

{1.56298, 0.93645, 1.01992}

3.9852

enter image description here

$\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.