# Discretisation of region intersection in 3D

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}]


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}]


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}]


• What is the question? – berniethejet Jul 21 '19 at 12:12
• I want to discretize all the RegionIntersections. Eventually I want to do this for irregular regions, and estimate the volume of the intersections. – JackySnoep Jul 21 '19 at 12:33
• 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. – rhermans Jul 21 '19 at 13:03
• OK, I added a separate paragraph with an explicit question – JackySnoep Jul 21 '19 at 13:13
• I have used Mathematica v12, on MacOS 10.14.5 – JackySnoep Jul 21 '19 at 14:32

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

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


• 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! – JackySnoep Jul 21 '19 at 14:46

You can use the function ToBoundaryMesh from the NDSolveFEM package:

Needs["NDSolveFEM"]

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

MeshRegion /@ tbm


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}]


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]


• 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.) – JackySnoep Jul 21 '19 at 15:40
• @JackySnoep, try ToElementMesh in place of ToBoundaryMesh – kglr Jul 21 '19 at 15:52

Needs["OpenCascadeLink"]
Needs["NDSolveFEM"]
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]]];