Construct a section (or slice) through 3D RegionsIntersection of a MeshRegion and InfinitePlaneUnnecessary...

What happened to my GE option?

How to access internet and run apt-get through a middle server?

Saint abbreviation

Existence of Riemann surface, holomorphic maps

Do authors have to be politically correct in article-writing?

Treasure Hunt Riddle

What makes papers publishable in top-tier journals?

Cat is tipping over bed-side lamps during the night

Citing paid articles from illegal web sharing

How to politely refuse in-office gym instructor for steroids and protein

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Square Root Distance from Integers

Why does PHOTOREC keep finding files?

Short story where statues have their heads replaced by those of carved insect heads

Separate environment for personal and development use under macOS

Most demanding German Newspapers

Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?

How much mayhem could I cause as a fish?

How do I append a character to the end of every line in an excel cell?

How to visualize the Riemann-Roch theorem from complex analysis or geometric topology considerations?

How do I prevent a homebrew Grappling Hook feature from trivializing Tomb of Annihilation?

Macro expansion inside href

How can I play a serial killer in a party of good PCs?



Construct a section (or slice) through 3D Regions


Intersection of a MeshRegion and InfinitePlaneUnnecessary and slow conversion between simple polygons and geometric regionsDraw filled regions in DateListPlotRegionPlot not plotting some regionsHandling Self-Intersecting RegionsHow to plot the difference between two regions?Trouble with discrete MeshRegions: Integrating over plane slicesUsing RegionIntersection on Regions formed by RegionUnionRegionIntersection of RegionsRegions, Mesh Regions, and GraphicsRegionUnion for 3D Regions













3












$begingroup$


I would like to draw a section through some 3D regions. I start by making some simple 3D regions as a minimum working example.



gg = BoundaryDiscretizeGraphics[
Graphics3D[#]] & /@ {Cuboid[{-0.2, -0.5, 0}, {0.2, 0.5, 0.5}],
Cone[{{1.5, 0, 0}, {2, 0, 2}}, 0.1] ,
Cylinder[{{2, 0, 1}, {3, 0, 0.5}}, 0.1], Sphere[{3, 0, 0}, 0.3],
Tube[{{0, 0, 0}, {4, 0, 3}}, 0.03]};
rr = RegionUnion[gg, Boxed -> True]


Mathematica graphics



Now I define an InfinitePlane that I would like to slice through my regions.



ip = InfinitePlane[{{0, 0, 0}, {4, 0, 0}, {4, 0, 1}}];
Show[
Graphics3D[ip],
Region[rr]
]


Mathematica graphics



How do I get the 2D Region lying in the plane? Is this possible?



This post has an approach for 3D primitives but I can't see how to extend this to 3D regions.



Edit



@kglr suggest I can go further with ClipPanes. Here is his suggestion.



rc = RegionPlot3D[rr, ClipPlanes -> ip, 
ClipPlanesStyle -> Opacity[0.1, Green]]


Mathematica graphics



This does the slicing and shows the insides but does not give me 2D regions. Could this be a starting point?



Edit 2



Continuing to take instructions from @kglr (see comments). He suggests finding the intersection with the mesh primitives.



dg = DiscretizeGraphics@
Quiet@Graphics3D[{DeleteCases[
RegionIntersection[ip, #] & /@
MeshPrimitives[rr,
2], _EmptyRegion | _Point | _RegionIntersection]}]


Mathematica graphics



One can then extract the lines and reduce the coordinates to the values in the plane.



LL = MeshPrimitives[dg, 1] /. {a_, b_, c_} -> {a, c};
Graphics[LL]


Mathematica graphics



This works. I will have to think further about what to do if the plane is not aligned with an axis. Reducing to 2D coordinates will then have to be done by a coordinate transform. However this is considerable progress and @kglr didn't have to post an answer!










share|improve this question











$endgroup$












  • $begingroup$
    maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
    $endgroup$
    – kglr
    4 hours ago










  • $begingroup$
    @kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
    $endgroup$
    – Hugh
    4 hours ago










  • $begingroup$
    dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
    $endgroup$
    – kglr
    4 hours ago
















3












$begingroup$


I would like to draw a section through some 3D regions. I start by making some simple 3D regions as a minimum working example.



gg = BoundaryDiscretizeGraphics[
Graphics3D[#]] & /@ {Cuboid[{-0.2, -0.5, 0}, {0.2, 0.5, 0.5}],
Cone[{{1.5, 0, 0}, {2, 0, 2}}, 0.1] ,
Cylinder[{{2, 0, 1}, {3, 0, 0.5}}, 0.1], Sphere[{3, 0, 0}, 0.3],
Tube[{{0, 0, 0}, {4, 0, 3}}, 0.03]};
rr = RegionUnion[gg, Boxed -> True]


Mathematica graphics



Now I define an InfinitePlane that I would like to slice through my regions.



ip = InfinitePlane[{{0, 0, 0}, {4, 0, 0}, {4, 0, 1}}];
Show[
Graphics3D[ip],
Region[rr]
]


Mathematica graphics



How do I get the 2D Region lying in the plane? Is this possible?



This post has an approach for 3D primitives but I can't see how to extend this to 3D regions.



Edit



@kglr suggest I can go further with ClipPanes. Here is his suggestion.



rc = RegionPlot3D[rr, ClipPlanes -> ip, 
ClipPlanesStyle -> Opacity[0.1, Green]]


Mathematica graphics



This does the slicing and shows the insides but does not give me 2D regions. Could this be a starting point?



Edit 2



Continuing to take instructions from @kglr (see comments). He suggests finding the intersection with the mesh primitives.



dg = DiscretizeGraphics@
Quiet@Graphics3D[{DeleteCases[
RegionIntersection[ip, #] & /@
MeshPrimitives[rr,
2], _EmptyRegion | _Point | _RegionIntersection]}]


Mathematica graphics



One can then extract the lines and reduce the coordinates to the values in the plane.



LL = MeshPrimitives[dg, 1] /. {a_, b_, c_} -> {a, c};
Graphics[LL]


Mathematica graphics



This works. I will have to think further about what to do if the plane is not aligned with an axis. Reducing to 2D coordinates will then have to be done by a coordinate transform. However this is considerable progress and @kglr didn't have to post an answer!










share|improve this question











$endgroup$












  • $begingroup$
    maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
    $endgroup$
    – kglr
    4 hours ago










  • $begingroup$
    @kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
    $endgroup$
    – Hugh
    4 hours ago










  • $begingroup$
    dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
    $endgroup$
    – kglr
    4 hours ago














3












3








3





$begingroup$


I would like to draw a section through some 3D regions. I start by making some simple 3D regions as a minimum working example.



gg = BoundaryDiscretizeGraphics[
Graphics3D[#]] & /@ {Cuboid[{-0.2, -0.5, 0}, {0.2, 0.5, 0.5}],
Cone[{{1.5, 0, 0}, {2, 0, 2}}, 0.1] ,
Cylinder[{{2, 0, 1}, {3, 0, 0.5}}, 0.1], Sphere[{3, 0, 0}, 0.3],
Tube[{{0, 0, 0}, {4, 0, 3}}, 0.03]};
rr = RegionUnion[gg, Boxed -> True]


Mathematica graphics



Now I define an InfinitePlane that I would like to slice through my regions.



ip = InfinitePlane[{{0, 0, 0}, {4, 0, 0}, {4, 0, 1}}];
Show[
Graphics3D[ip],
Region[rr]
]


Mathematica graphics



How do I get the 2D Region lying in the plane? Is this possible?



This post has an approach for 3D primitives but I can't see how to extend this to 3D regions.



Edit



@kglr suggest I can go further with ClipPanes. Here is his suggestion.



rc = RegionPlot3D[rr, ClipPlanes -> ip, 
ClipPlanesStyle -> Opacity[0.1, Green]]


Mathematica graphics



This does the slicing and shows the insides but does not give me 2D regions. Could this be a starting point?



Edit 2



Continuing to take instructions from @kglr (see comments). He suggests finding the intersection with the mesh primitives.



dg = DiscretizeGraphics@
Quiet@Graphics3D[{DeleteCases[
RegionIntersection[ip, #] & /@
MeshPrimitives[rr,
2], _EmptyRegion | _Point | _RegionIntersection]}]


Mathematica graphics



One can then extract the lines and reduce the coordinates to the values in the plane.



LL = MeshPrimitives[dg, 1] /. {a_, b_, c_} -> {a, c};
Graphics[LL]


Mathematica graphics



This works. I will have to think further about what to do if the plane is not aligned with an axis. Reducing to 2D coordinates will then have to be done by a coordinate transform. However this is considerable progress and @kglr didn't have to post an answer!










share|improve this question











$endgroup$




I would like to draw a section through some 3D regions. I start by making some simple 3D regions as a minimum working example.



gg = BoundaryDiscretizeGraphics[
Graphics3D[#]] & /@ {Cuboid[{-0.2, -0.5, 0}, {0.2, 0.5, 0.5}],
Cone[{{1.5, 0, 0}, {2, 0, 2}}, 0.1] ,
Cylinder[{{2, 0, 1}, {3, 0, 0.5}}, 0.1], Sphere[{3, 0, 0}, 0.3],
Tube[{{0, 0, 0}, {4, 0, 3}}, 0.03]};
rr = RegionUnion[gg, Boxed -> True]


Mathematica graphics



Now I define an InfinitePlane that I would like to slice through my regions.



ip = InfinitePlane[{{0, 0, 0}, {4, 0, 0}, {4, 0, 1}}];
Show[
Graphics3D[ip],
Region[rr]
]


Mathematica graphics



How do I get the 2D Region lying in the plane? Is this possible?



This post has an approach for 3D primitives but I can't see how to extend this to 3D regions.



Edit



@kglr suggest I can go further with ClipPanes. Here is his suggestion.



rc = RegionPlot3D[rr, ClipPlanes -> ip, 
ClipPlanesStyle -> Opacity[0.1, Green]]


Mathematica graphics



This does the slicing and shows the insides but does not give me 2D regions. Could this be a starting point?



Edit 2



Continuing to take instructions from @kglr (see comments). He suggests finding the intersection with the mesh primitives.



dg = DiscretizeGraphics@
Quiet@Graphics3D[{DeleteCases[
RegionIntersection[ip, #] & /@
MeshPrimitives[rr,
2], _EmptyRegion | _Point | _RegionIntersection]}]


Mathematica graphics



One can then extract the lines and reduce the coordinates to the values in the plane.



LL = MeshPrimitives[dg, 1] /. {a_, b_, c_} -> {a, c};
Graphics[LL]


Mathematica graphics



This works. I will have to think further about what to do if the plane is not aligned with an axis. Reducing to 2D coordinates will then have to be done by a coordinate transform. However this is considerable progress and @kglr didn't have to post an answer!







regions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago







Hugh

















asked 5 hours ago









HughHugh

6,39521945




6,39521945












  • $begingroup$
    maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
    $endgroup$
    – kglr
    4 hours ago










  • $begingroup$
    @kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
    $endgroup$
    – Hugh
    4 hours ago










  • $begingroup$
    dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
    $endgroup$
    – kglr
    4 hours ago


















  • $begingroup$
    maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
    $endgroup$
    – kglr
    4 hours ago










  • $begingroup$
    @kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
    $endgroup$
    – Hugh
    4 hours ago










  • $begingroup$
    dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
    $endgroup$
    – kglr
    4 hours ago
















$begingroup$
maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
$endgroup$
– kglr
4 hours ago




$begingroup$
maybe RegionPlot3D[rr, ClipPlanes -> ip, ClipPlanesStyle -> Opacity[.5, Red]]?
$endgroup$
– kglr
4 hours ago












$begingroup$
@kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
$endgroup$
– Hugh
4 hours ago




$begingroup$
@kglr Thanks. This gives me a nice slice but how do I extract the lines on the plane and form regions?
$endgroup$
– Hugh
4 hours ago












$begingroup$
dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
$endgroup$
– kglr
4 hours ago




$begingroup$
dg = DiscretizeGraphics@ Quiet@Graphics3D[{DeleteCases[ RegionIntersection[ip, #] & /@ MeshPrimitives[rr, 2], _EmptyRegion | _Point | _RegionIntersection]}] gives lines which can be further processed to form the polygons.
$endgroup$
– kglr
4 hours ago










1 Answer
1






active

oldest

votes


















4












$begingroup$

Note that RegionIntersection[rr, ip] should give you what you want here but doesn't.



Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion:



cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2`, 4.1`}, {-0.5`, 0}, {-0.3`, 3.1`}}];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



We can easily project to 2d as well:



BoundaryMeshRegion[MeshCoordinates[cut][[All, {1, 3}]], holes]


enter image description here





We can adapt this idea to any plane. I'll use HalfSpace to emphasize which side of the plane is kept.



halfSpaceClip[reg_, ___] /; !MeshRegionQ[reg] && !BoundaryMeshRegionQ[reg] && RegionEmbeddingDimension[reg] != 3 = $Failed;

halfSpaceClip[mr_, h_HalfSpace] /; RegionWithin[h, mr] := mr

halfSpaceClip[mr_, HalfSpace[n_, p_]] /; RegionWithin[HalfSpace[-n, p], mr] = EmptyRegion[3];

halfSpaceClip[mr_, HalfSpace[n_, p_]] :=
Block[{rt, rot, bds, clip},
rt = RotationTransform[{n, {0, 0, -1}}, p];
rot = TransformedRegion[mr, rt];
bds = RegionBounds[rot];

clip = DiscretizeRegion[rot, {#1+5{-1,1}, #2+5{-1,1}, {p[[3]], #3[[2]]+5}}]& @@ bds;

InverseTransformedRegion[clip, rt]
]

halfSpaceClip[___] = $Failed;


The same example:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{0, 1, 0}, {0, 0, 0}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



A non axes aligned plane:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{.5, 1, -1}, {0, .5, .5}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
    $endgroup$
    – Hugh
    3 hours ago










  • $begingroup$
    @Hugh Yes that is one way. See my latest edit.
    $endgroup$
    – Chip Hurst
    3 hours ago










  • $begingroup$
    Excellent many thanks.
    $endgroup$
    – Hugh
    3 hours ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192263%2fconstruct-a-section-or-slice-through-3d-regions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4












$begingroup$

Note that RegionIntersection[rr, ip] should give you what you want here but doesn't.



Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion:



cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2`, 4.1`}, {-0.5`, 0}, {-0.3`, 3.1`}}];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



We can easily project to 2d as well:



BoundaryMeshRegion[MeshCoordinates[cut][[All, {1, 3}]], holes]


enter image description here





We can adapt this idea to any plane. I'll use HalfSpace to emphasize which side of the plane is kept.



halfSpaceClip[reg_, ___] /; !MeshRegionQ[reg] && !BoundaryMeshRegionQ[reg] && RegionEmbeddingDimension[reg] != 3 = $Failed;

halfSpaceClip[mr_, h_HalfSpace] /; RegionWithin[h, mr] := mr

halfSpaceClip[mr_, HalfSpace[n_, p_]] /; RegionWithin[HalfSpace[-n, p], mr] = EmptyRegion[3];

halfSpaceClip[mr_, HalfSpace[n_, p_]] :=
Block[{rt, rot, bds, clip},
rt = RotationTransform[{n, {0, 0, -1}}, p];
rot = TransformedRegion[mr, rt];
bds = RegionBounds[rot];

clip = DiscretizeRegion[rot, {#1+5{-1,1}, #2+5{-1,1}, {p[[3]], #3[[2]]+5}}]& @@ bds;

InverseTransformedRegion[clip, rt]
]

halfSpaceClip[___] = $Failed;


The same example:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{0, 1, 0}, {0, 0, 0}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



A non axes aligned plane:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{.5, 1, -1}, {0, .5, .5}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
    $endgroup$
    – Hugh
    3 hours ago










  • $begingroup$
    @Hugh Yes that is one way. See my latest edit.
    $endgroup$
    – Chip Hurst
    3 hours ago










  • $begingroup$
    Excellent many thanks.
    $endgroup$
    – Hugh
    3 hours ago
















4












$begingroup$

Note that RegionIntersection[rr, ip] should give you what you want here but doesn't.



Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion:



cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2`, 4.1`}, {-0.5`, 0}, {-0.3`, 3.1`}}];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



We can easily project to 2d as well:



BoundaryMeshRegion[MeshCoordinates[cut][[All, {1, 3}]], holes]


enter image description here





We can adapt this idea to any plane. I'll use HalfSpace to emphasize which side of the plane is kept.



halfSpaceClip[reg_, ___] /; !MeshRegionQ[reg] && !BoundaryMeshRegionQ[reg] && RegionEmbeddingDimension[reg] != 3 = $Failed;

halfSpaceClip[mr_, h_HalfSpace] /; RegionWithin[h, mr] := mr

halfSpaceClip[mr_, HalfSpace[n_, p_]] /; RegionWithin[HalfSpace[-n, p], mr] = EmptyRegion[3];

halfSpaceClip[mr_, HalfSpace[n_, p_]] :=
Block[{rt, rot, bds, clip},
rt = RotationTransform[{n, {0, 0, -1}}, p];
rot = TransformedRegion[mr, rt];
bds = RegionBounds[rot];

clip = DiscretizeRegion[rot, {#1+5{-1,1}, #2+5{-1,1}, {p[[3]], #3[[2]]+5}}]& @@ bds;

InverseTransformedRegion[clip, rt]
]

halfSpaceClip[___] = $Failed;


The same example:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{0, 1, 0}, {0, 0, 0}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



A non axes aligned plane:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{.5, 1, -1}, {0, .5, .5}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
    $endgroup$
    – Hugh
    3 hours ago










  • $begingroup$
    @Hugh Yes that is one way. See my latest edit.
    $endgroup$
    – Chip Hurst
    3 hours ago










  • $begingroup$
    Excellent many thanks.
    $endgroup$
    – Hugh
    3 hours ago














4












4








4





$begingroup$

Note that RegionIntersection[rr, ip] should give you what you want here but doesn't.



Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion:



cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2`, 4.1`}, {-0.5`, 0}, {-0.3`, 3.1`}}];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



We can easily project to 2d as well:



BoundaryMeshRegion[MeshCoordinates[cut][[All, {1, 3}]], holes]


enter image description here





We can adapt this idea to any plane. I'll use HalfSpace to emphasize which side of the plane is kept.



halfSpaceClip[reg_, ___] /; !MeshRegionQ[reg] && !BoundaryMeshRegionQ[reg] && RegionEmbeddingDimension[reg] != 3 = $Failed;

halfSpaceClip[mr_, h_HalfSpace] /; RegionWithin[h, mr] := mr

halfSpaceClip[mr_, HalfSpace[n_, p_]] /; RegionWithin[HalfSpace[-n, p], mr] = EmptyRegion[3];

halfSpaceClip[mr_, HalfSpace[n_, p_]] :=
Block[{rt, rot, bds, clip},
rt = RotationTransform[{n, {0, 0, -1}}, p];
rot = TransformedRegion[mr, rt];
bds = RegionBounds[rot];

clip = DiscretizeRegion[rot, {#1+5{-1,1}, #2+5{-1,1}, {p[[3]], #3[[2]]+5}}]& @@ bds;

InverseTransformedRegion[clip, rt]
]

halfSpaceClip[___] = $Failed;


The same example:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{0, 1, 0}, {0, 0, 0}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



A non axes aligned plane:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{.5, 1, -1}, {0, .5, .5}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here






share|improve this answer











$endgroup$



Note that RegionIntersection[rr, ip] should give you what you want here but doesn't.



Since we have an axes aligned plane, we can workaround this by exploiting the second argument of DiscretizeRegion:



cut = DiscretizeRegion[RegionBoundary[rr], {{-0.2`, 4.1`}, {-0.5`, 0}, {-0.3`, 3.1`}}];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



We can easily project to 2d as well:



BoundaryMeshRegion[MeshCoordinates[cut][[All, {1, 3}]], holes]


enter image description here





We can adapt this idea to any plane. I'll use HalfSpace to emphasize which side of the plane is kept.



halfSpaceClip[reg_, ___] /; !MeshRegionQ[reg] && !BoundaryMeshRegionQ[reg] && RegionEmbeddingDimension[reg] != 3 = $Failed;

halfSpaceClip[mr_, h_HalfSpace] /; RegionWithin[h, mr] := mr

halfSpaceClip[mr_, HalfSpace[n_, p_]] /; RegionWithin[HalfSpace[-n, p], mr] = EmptyRegion[3];

halfSpaceClip[mr_, HalfSpace[n_, p_]] :=
Block[{rt, rot, bds, clip},
rt = RotationTransform[{n, {0, 0, -1}}, p];
rot = TransformedRegion[mr, rt];
bds = RegionBounds[rot];

clip = DiscretizeRegion[rot, {#1+5{-1,1}, #2+5{-1,1}, {p[[3]], #3[[2]]+5}}]& @@ bds;

InverseTransformedRegion[clip, rt]
]

halfSpaceClip[___] = $Failed;


The same example:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{0, 1, 0}, {0, 0, 0}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here



A non axes aligned plane:



cut = halfSpaceClip[RegionBoundary[rr], HalfSpace[{.5, 1, -1}, {0, .5, .5}]];

holes = FindMeshDefects[cut, "HoleEdges", "Cell"]["HoleEdges"];

slice = MeshRegion[MeshCoordinates[cut], holes, PlotTheme -> "Lines",
MeshCellStyle -> {1 -> Black}];

Show[slice, BoundaryMeshRegion[rr, BaseStyle -> Opacity[.3]]]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 3 hours ago

























answered 4 hours ago









Chip HurstChip Hurst

21.8k15790




21.8k15790












  • $begingroup$
    Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
    $endgroup$
    – Hugh
    3 hours ago










  • $begingroup$
    @Hugh Yes that is one way. See my latest edit.
    $endgroup$
    – Chip Hurst
    3 hours ago










  • $begingroup$
    Excellent many thanks.
    $endgroup$
    – Hugh
    3 hours ago


















  • $begingroup$
    Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
    $endgroup$
    – Hugh
    3 hours ago










  • $begingroup$
    @Hugh Yes that is one way. See my latest edit.
    $endgroup$
    – Chip Hurst
    3 hours ago










  • $begingroup$
    Excellent many thanks.
    $endgroup$
    – Hugh
    3 hours ago
















$begingroup$
Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
$endgroup$
– Hugh
3 hours ago




$begingroup$
Thanks. This works. How do you deal with a plane not aligned with the axis? Is a coordinate transformation of the axis is needed?
$endgroup$
– Hugh
3 hours ago












$begingroup$
@Hugh Yes that is one way. See my latest edit.
$endgroup$
– Chip Hurst
3 hours ago




$begingroup$
@Hugh Yes that is one way. See my latest edit.
$endgroup$
– Chip Hurst
3 hours ago












$begingroup$
Excellent many thanks.
$endgroup$
– Hugh
3 hours ago




$begingroup$
Excellent many thanks.
$endgroup$
– Hugh
3 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192263%2fconstruct-a-section-or-slice-through-3d-regions%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Webac Holding Inhaltsverzeichnis Geschichte | Organisationsstruktur | Tochterfirmen |...

What's the meaning of a knight fighting a snail in medieval book illustrations?What is the meaning of a glove...

Salamanca Inhaltsverzeichnis Lage und Klima | Bevölkerungsentwicklung | Geschichte | Kultur und...