Picking mesh elements that are not on the border of the mesh

Clash Royale CLAN TAG#URR8PPP
$begingroup$
As an example, let's say I use a set of random points to create a Voronoi mesh
pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]
and get something that looks like this:

My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.
performance-tuning mesh
$endgroup$
add a comment |
$begingroup$
As an example, let's say I use a set of random points to create a Voronoi mesh
pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]
and get something that looks like this:

My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.
performance-tuning mesh
$endgroup$
$begingroup$
RegionBoundary? To get coordinates you can doRegionBoundary@mesh // MeshCoordinates
$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53
add a comment |
$begingroup$
As an example, let's say I use a set of random points to create a Voronoi mesh
pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]
and get something that looks like this:

My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.
performance-tuning mesh
$endgroup$
As an example, let's say I use a set of random points to create a Voronoi mesh
pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]
and get something that looks like this:

My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.
performance-tuning mesh
performance-tuning mesh
asked Jan 7 at 22:30
Aaron StevensAaron Stevens
319110
319110
$begingroup$
RegionBoundary? To get coordinates you can doRegionBoundary@mesh // MeshCoordinates
$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53
add a comment |
$begingroup$
RegionBoundary? To get coordinates you can doRegionBoundary@mesh // MeshCoordinates
$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53
$begingroup$
RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]

Related: Boundary cells of a mesh?
Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]

$endgroup$
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page ofMeshCellIndexdoes not show it as example...
$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned byvm["Properties"]:)
$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
add a comment |
$begingroup$
For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually
R["InteriorFaces"]
should work.
A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:
Needs["IGraphM`"]
A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];
HighlightMesh[R, Thread[2, interiorfaces]]

$endgroup$
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189008%2fpicking-mesh-elements-that-are-not-on-the-border-of-the-mesh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]

Related: Boundary cells of a mesh?
Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]

$endgroup$
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page ofMeshCellIndexdoes not show it as example...
$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned byvm["Properties"]:)
$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
add a comment |
$begingroup$
vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]

Related: Boundary cells of a mesh?
Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]

$endgroup$
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page ofMeshCellIndexdoes not show it as example...
$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned byvm["Properties"]:)
$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
add a comment |
$begingroup$
vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]

Related: Boundary cells of a mesh?
Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]

$endgroup$
vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]

Related: Boundary cells of a mesh?
Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]

edited Jan 7 at 22:56
answered Jan 7 at 22:52
kglrkglr
180k9200413
180k9200413
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page ofMeshCellIndexdoes not show it as example...
$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned byvm["Properties"]:)
$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
add a comment |
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page ofMeshCellIndexdoes not show it as example...
$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned byvm["Properties"]:)
$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
$begingroup$
Yep that was the simple answer I was expecting haha. Thanks!
$endgroup$
– Aaron Stevens
Jan 7 at 22:55
2
2
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page of
MeshCellIndex does not show it as example...$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
$begingroup$
@kglr Wow, I'm impressed. Where did you find this syntax? The doc page of
MeshCellIndex does not show it as example...$endgroup$
– Henrik Schumacher
Jan 7 at 23:29
1
1
$begingroup$
@HenrikSchumacher, blind search trying some objects returned by
vm["Properties"]:)$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher, blind search trying some objects returned by
vm["Properties"]:)$endgroup$
– kglr
Jan 8 at 0:00
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
$begingroup$
@HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
$endgroup$
– Aaron Stevens
Jan 8 at 12:45
add a comment |
$begingroup$
For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually
R["InteriorFaces"]
should work.
A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:
Needs["IGraphM`"]
A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];
HighlightMesh[R, Thread[2, interiorfaces]]

$endgroup$
add a comment |
$begingroup$
For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually
R["InteriorFaces"]
should work.
A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:
Needs["IGraphM`"]
A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];
HighlightMesh[R, Thread[2, interiorfaces]]

$endgroup$
add a comment |
$begingroup$
For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually
R["InteriorFaces"]
should work.
A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:
Needs["IGraphM`"]
A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];
HighlightMesh[R, Thread[2, interiorfaces]]

$endgroup$
For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually
R["InteriorFaces"]
should work.
A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:
Needs["IGraphM`"]
A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];
HighlightMesh[R, Thread[2, interiorfaces]]

answered Jan 7 at 22:46
Henrik SchumacherHenrik Schumacher
51.1k469146
51.1k469146
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189008%2fpicking-mesh-elements-that-are-not-on-the-border-of-the-mesh%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$begingroup$
RegionBoundary? To get coordinates you can doRegionBoundary@mesh // MeshCoordinates$endgroup$
– b3m2a1
Jan 7 at 22:45
$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52
$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53