5

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

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

Voronoi interior

and I can keep with the orange diagrams

selected cells

but I don't know how to calculate the total length of the edges of the last graphic. Any suggestions?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Mati Ger
  • 143
  • 4
  • 1
    Can you add the code to select the inner cells and the definition of pts? – MarcoB Mar 07 '19 at 21:01
  • The distribution of points pts comes from a picture but could be random numbers. For example:

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

    xy = VoronoiMesh[pts, {{0, 1}, {0, 1}}];

    i2 = MeshCellIndex[xy, {2, "Interior"}] ;

    HighlightMesh[xy, Style[i2, LightOrange]]

    – Mati Ger Mar 07 '19 at 21:40

1 Answers1

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

"Interior"

HighlightMesh[vm, Style[MeshCellIndex[vm, {1, "Interior"}], Red]]

enter image description here

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]]

enter image description here

Total[ArcLength /@ MeshPrimitives[vm, {1, "Boundary"}]]

5.92015

"Frontier"

HighlightMesh[vm, Style[MeshCellIndex[vm, {1, "Frontier"}], Red]]

enter image description here

Total[ArcLength /@ MeshPrimitives[vm, {1, "Frontier"}]]

5.357575

All lines

Total[vm["EdgeLengths"]]

30.75167

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

30.751672460568727

kglr
  • 394,356
  • 18
  • 477
  • 896