5
$\begingroup$

Context

This is fairly general and simple question, (probably because it has a simple solution?). I want to define a mesh (e.g. to be used with Plot3D or FEM or whatever) as the cross section of a surface and a volume. For instance a ball and a plane.

Question

How can I define a mesh on a 2D intersection of two 3D objects?

or its simpler version

How can I define a mesh on a 2D plane intersection through a 3D object?

Attempt

R=RegionIntersection[Ball[],InfinitePlane[{0,0,0},{{1,0,0},{0,1,0}}];
Plot3D[x^2+y^2,{x, y} \[Element] R]

does not work, neither does

  Needs["NDSolve`FEM`"]
  ToElementMesh[R]

while

 R // Region

enter image description here

is well defined.

I believe this would be super handy to e.g. to investigate volumes?

Thanks for your help!

$\endgroup$
8
$\begingroup$

One can use DiscretizeRegion to obtain a mesh:

slice = DiscretizeRegion[
  RegionIntersection[
    Ball[], 
    InfinitePlane[{0, 0, 0}, {{1, 0, 0}, {0, 1, 0}}]
  ], 
  MeshCellStyle -> {1 -> Black}
]

Or SliceDensityPlot3D to get a visual:

SliceDensityPlot3D[1, {"ZStackedPlanes", 10}, {x, y, z} ∈ Ball[], Axes -> False, Boxed -> False]


3D surface plotters like Plot3D can plot over 2D regions. We can take slice and project to 2D:

slice2d = MeshRegion[MeshCoordinates[slice][[All, 1;;2]], MeshCells[slice, 2]];

Plot3D[x^2 + y^2, {x, y} ∈ slice2d]

If the 3D slice lies in a different cardinal plane, we'll need to project with different coordinate indices. Here's an example over a y-z plane:

reg = ImplicitRegion[(x^2 + 9/4 y^2 + z^2 - 1)^3 - x^2 z^3 - 9/80 y^2 z^3 <= 0, {x, y, z}]; 
slice = DiscretizeRegion[RegionIntersection[reg, 
  InfinitePlane[{0, 0, 0}, {{0, 1, 0}, {0, 0, 1}}]]];

slice2d = MeshRegion[MeshCoordinates[slice][[All, {2, 3}]], MeshCells[slice, 2]];

Plot3D[x^2 + y^2, {x, y} ∈ slice2d]

| improve this answer | |
$\endgroup$
5
$\begingroup$

Note that your region has

RegionBounds[R]
{{-1, 1}, {-1, 1}, {0, 0}}

This is why the FEM mesh generation complains. See that this works:

Needs["NDSolve`FEM`"]
ToBoundaryMesh[R, {{-1, 1}, {-1, 1}, {-1, 1}}]["Wireframe"]

enter image description here

Note the difference in behavior for the embedding dimension of the returned object between DiscretizeRegion and the ElementMesh family of functions.

Now, let us consider a different R. You can visualize the computed values on the intersection.

R = RegionIntersection[Ball[], 
   InfinitePlane[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]];
Show[
 Graphics3D[{Opacity[0.5], Ball[]}],
 SliceContourPlot3D[Exp[-(x^2 + y^2 + z^2)], 
  R, {x, y, z} \[Element] Ball[]], Boxed -> False]

enter image description here

To refine the contours the Contour option can be used:

Show[Graphics3D[{Opacity[0.25], Ball[]}], 
 SliceContourPlot3D[Exp[-(x^2 + y^2 + z^2)], 
  R, {x, y, z} \[Element] Ball[], Contours -> 25], Boxed -> False]

enter image description here

You can also specify a MeshRegion

R = RegionIntersection[Ball[], 
   InfinitePlane[{{1, 0, 0}, {1, 1, 1}, {0, 0, 1}}]];
Show[Graphics3D[{Opacity[0.25], Ball[]}], 
 SliceContourPlot3D[Exp[-(x^2 + y^2 + z^2)], 
  DiscretizeRegion[R], {x, y, z} \[Element] Ball[], Contours -> 25], 
 Boxed -> False]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ @chris, give it to Chip. I copied the RegionIntersection from him, since there is a syntax error in yours ;-) $\endgroup$ – user21 Apr 3 at 14:27
  • $\begingroup$ Oops. How would you refine the quality of the contours? $\endgroup$ – chris Apr 3 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.