1

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?

Mr Puh
  • 1,017
  • 6
  • 12
  • 1
    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. – Daniel Huber Sep 15 '20 at 20:29
  • 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. – Chris Sep 15 '20 at 23:38
  • 1
    I think you've found a bug. DiscretizeRegion should work. – m_goldberg Sep 16 '20 at 03:43
  • @Chris : I just dragged a file into the browser. – Mr Puh Sep 21 '20 at 12:04
  • @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? – Mr Puh Sep 21 '20 at 12:05
  • @MrPuh. A displacement of .01 requires a very fine mesh. When the two plates are fully aligned, then the union is sane as one of the plates and so the mesh that worked for one of the plates will work for the union. I think that might be the issue or part of it, but can' t be sure. Suggest you contact Wolfram tech support. – m_goldberg Sep 21 '20 at 14:28

1 Answers1

2

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

Mauricio Fernández
  • 5,463
  • 21
  • 45