6
$\begingroup$

Does anyone have any suggestions how to determine the total sum of edges length in a Voronoi diagram?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE. Are you sure you are posting on the right site? There is nothing in your question making it clear that it is concerned with Mathematica software. $\endgroup$ – m_goldberg Feb 25 at 22:48
8
$\begingroup$
SeedRandom[1234];
R = VoronoiMesh[RandomReal[{-1, 1}, {20, 2}]];
Total[PropertyValue[{R, 1}, MeshCellMeasure]]

31.1601

$\endgroup$
  • $\begingroup$ I am very grateful for your response, Henrik. Thank you. $\endgroup$ – Mati Ger Feb 26 at 22:47
  • $\begingroup$ Great to hear that! You're welcome. $\endgroup$ – Henrik Schumacher Feb 26 at 22:48
8
$\begingroup$
SeedRandom[1]
pts = RandomReal[{-1, 1}, {5, 2}];
vm = VoronoiMesh[pts]

You can use the property "EdgeLengths":

Total @ vm["EdgeLengths"]

12.2894

If you need the lengths of individual edges:

lengths = RegionMeasure /@ MeshPrimitives[vm, 1]

{0.60034, 0.672996, 0.403197, 0.793131, 0.596543, 0.920977, 1.03974, 1.12238, 0.322772, 1.05995, 0.854316, 0.985915, 0.0806386, 0.844254, 0.264125, 1.72809}

Total[lengths]

12.2894

Alternatively, you can use ArcLength in place of RegionMeasure:

lengths == ArcLength /@ MeshPrimitives[vm, 1]
True
$\endgroup$
  • $\begingroup$ Thank you very much for your response, it has been very helpful for me. $\endgroup$ – Mati Ger Feb 26 at 22:44
  • $\begingroup$ @MatiGer, you are most welcome. $\endgroup$ – kglr Feb 26 at 22:51

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.