9
$\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:

enter image description here

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.

$\endgroup$
  • $\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$ 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
9
$\begingroup$
vm = VoronoiMesh[pts, {-1, 1}]
HighlightMesh[vm, MeshCellIndex[vm, {2, "Interior"}]]

enter image description here

Related: Boundary cells of a mesh?

Show[vm, Epilog -> {Opacity[.7, Orange], MeshPrimitives[vm, {2, "Interior"}]}]

enter image description here

$\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 of MeshCellIndex does not show it as example... $\endgroup$ – Henrik Schumacher Jan 7 at 23:29
  • 1
    $\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
7
$\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}]]

enter image description here

$\endgroup$

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.