# Calculate total length of edges in select Voronoi diagram

I want to calculate the total length of edges in a Voronoi diagram like this I can calculate this with

lengths = RegionMeasure /@ MeshPrimitives[VoronoiMesh[pts], 1];

Total[lengths]


but, I want to eliminate from the calculation the diagrams touching the border of the image. I can select this diagrams like here and I can keep with the orange diagrams but I don't know how to calculate the total length of the edges of the last graphic. Any suggestions?

• Can you add the code to select the inner cells and the definition of pts? Mar 7, 2019 at 21:01
• The distribution of points pts comes from a picture but could be random numbers. For example: SeedRandom pts = RandomReal[1, {100, 2}]; xy = VoronoiMesh[pts, {{0, 1}, {0, 1}}]; i2 = MeshCellIndex[xy, {2, "Interior"}] ; HighlightMesh[xy, Style[i2, LightOrange]] Mar 7, 2019 at 21:40

SeedRandom
pts = RandomReal[1, {100, 2}];
vm = VoronoiMesh[pts];


### "Interior"

HighlightMesh[vm, Style[MeshCellIndex[vm, {1, "Interior"}], Red]] Total[ArcLength /@ MeshPrimitives[vm , {1, "Interior"}]]


19.4739

Alternatively,

Total[RegionMeasure /@ MeshPrimitives[vm, {1, "Interior"}]]


19.4739

RegionMeasure[MeshRegion[MeshCoordinates[vm], MeshCells[vm, {1, "Interior"}]]]


19.4739

### "Boundary"

HighlightMesh[vm, Style[MeshCellIndex[vm, {1, "Boundary"}], Red]] Total[ArcLength /@ MeshPrimitives[vm, {1, "Boundary"}]]


5.92015

### "Frontier"

HighlightMesh[vm, Style[MeshCellIndex[vm, {1, "Frontier"}], Red]] Total[ArcLength /@ MeshPrimitives[vm, {1, "Frontier"}]]


5.357575

### All lines

Total[vm["EdgeLengths"]]


30.75167

Total[ArcLength /@ MeshPrimitives[vm , 1]]


30.751672460568727

• So long as none of the cells adjacent to the boundary aren't in fact the full Voronoi cell. This would only happen in contrived cases though. Mar 7, 2019 at 21:23
• @ChipHurst, good point.
– kglr
Mar 7, 2019 at 21:25
• I am impressed by the speed and clarity in your response, kglr. I am very grateful with you. Thank you. Mar 7, 2019 at 21:48
• @MatiGer, my pleasure. Thank you for the kind words and accept.
– kglr
Mar 7, 2019 at 22:00