8
$\begingroup$

If I try to discretise the intersection (BoundaryDiscretizeRegion), of a shell in a cuboid, some of the regions (that are found with RegionIntersection) are lost in the discretising process. I tried several of the options for BoundaryDiscretizeRegion but none seem to give me both the regions back.

iShell = Table[SphericalShell[{0, 0, 0}, {(i - 1) 0.1, i 0.1}], {i, 50}];
regInt = Table[RegionIntersection[iShell[[i]], 
Cuboid[{-1, -4, -1}, {1, 4, 1}]], {i, Length[iShell]}];

RegionIntersection finds the regions:

Table[Region[regInt[[i]]], {i, 27, 29}]

enter image description here

But if I discretise them some are lost, (the MaxCellMeasure setting makes that the regions are properly resolved):

intDisc = Table[BoundaryDiscretizeRegion[regInt[[i]],MaxCellMeasure -> .01], {i, 27, 29}]

enter image description here

My question is: How can I make sure that BoundaryDiscretizeRegion digitises all the regions that were detected with RegionIntersection?

The picture below is just to show the context, the first figure has both regions digitised, the second only one of the regions:

pic = Table[Graphics3D[{intDisc[[i]], Opacity[0.5], iShell[[i + 26]], 
Cuboid[{-1, -4, -1}, {1, 4, 1}]}, Boxed -> False], {i, 2}]

enter image description here

$\endgroup$
5
  • 1
    $\begingroup$ What is the question? $\endgroup$ Commented Jul 21, 2019 at 12:12
  • $\begingroup$ I want to discretize all the RegionIntersections. Eventually I want to do this for irregular regions, and estimate the volume of the intersections. $\endgroup$
    – JackySnoep
    Commented Jul 21, 2019 at 12:33
  • $\begingroup$ Hi JackySnoep, welcome to Mma.SE. Thanks for taking the tour. Be sure you have learning about asking and what's on-topic. I think it's important that you state the question clearly within the question text in an independent paragraph, not only in the comments. A clear question is more likely to inspire a prompt answer. $\endgroup$
    – rhermans
    Commented Jul 21, 2019 at 13:03
  • 1
    $\begingroup$ OK, I added a separate paragraph with an explicit question $\endgroup$
    – JackySnoep
    Commented Jul 21, 2019 at 13:13
  • $\begingroup$ I have used Mathematica v12, on MacOS 10.14.5 $\endgroup$
    – JackySnoep
    Commented Jul 21, 2019 at 14:32

3 Answers 3

4
$\begingroup$

As a workaround you can use the second argument of BoundaryDiscretizeRegion:

Table[BoundaryDiscretizeRegion[iShell[[i]], {{-1, 1}, {-4, 4}, {-1, 1}}], {i, 27, 29}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks, and importantly it also works if I apply BoundaryDiscretizeRegion on regInt[[I]], not only on iShell[[I]]. I want to use the function for irregular regions and must use RegionIntersection, (i.e. I cannot depend on rectangular bounds to define the intersection). Indeed, it is a workaround, but it helps me for now! $\endgroup$
    – JackySnoep
    Commented Jul 21, 2019 at 14:46
4
$\begingroup$

The new in 12.1 OpenCascadeLink is doing much better at this:

Needs["OpenCascadeLink`"]
Needs["NDSolve`FEM`"]
iShell = Table[
   SphericalShell[{0, 0, 0}, {(i - 1) 0.1, i 0.1}], {i, 50}];
regInt = Table[
   RegionIntersection[iShell[[i]], 
    Cuboid[{-1, -4, -1}, {1, 4, 1}]], {i, Length[iShell]}];

We choose one of them:

ocr = OpenCascadeShape[regInt[[29]]];
bmeshOC = OpenCascadeShapeSurfaceMeshToBoundaryMesh[ocr];
bmeshOC["Wireframe"[
  "MeshElementStyle" -> Directive[FaceForm[Green], EdgeForm[Red]]]]

enter image description here

$\endgroup$
3
$\begingroup$

You can use the function ToBoundaryMesh from the NDSolve`FEM package:

Needs["NDSolve`FEM`"]

tbm = Table[ToBoundaryMesh[regInt[[i]], MaxCellMeasure -> {"Length" -> .1}], {i, 27, 29}];

MeshRegion /@ tbm

enter image description here

Row @ Table[Graphics3D[{ Opacity[0.25], iShell[[i + 26]], 
    Cuboid[{-1, -4, -1}, {1, 4, 1}], 
    EdgeForm[], Opacity[1], 
    FaceForm[Red, Red], ElementMeshToGraphicsComplex @ tbm[[i]]}, 
   Boxed -> False], {i, 2}]

enter image description here

Update: You can also use ToElementMesh:

m28 = ToElementMesh[regInt[[28]], MaxCellMeasure -> {"Length" -> .1},
   "MaxBoundaryCellMeasure" -> 0.02];

RegionDimension @ MeshRegion @ m28

3

Volume @ MeshRegion @ m28

0.839001

Graphics3D[{EdgeForm[], FaceForm[Red], ElementMeshToGraphicsComplex[m28]}, 
  Boxed -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ Nice, this solves the issues and I do not need to give boundary constraints. But the MeshRegion of the ToBoundaryMesh has dimension 2, how do I get the volume of the region? (Strangely, the dimension of the BoundaryDiscretizeRegion, as used above, is 3. Then I can simply use the Volume function.) $\endgroup$
    – JackySnoep
    Commented Jul 21, 2019 at 15:40
  • 1
    $\begingroup$ @JackySnoep, try ToElementMesh in place of ToBoundaryMesh $\endgroup$
    – kglr
    Commented Jul 21, 2019 at 15:52

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.