9

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.

BioPhysicist
  • 1,124
  • 5
  • 16

2 Answers2

10
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

kglr
  • 394,356
  • 18
  • 477
  • 896
8

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

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309