Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Does anyone have any suggestions how to determine the perimeter, area and number of sides of each Voronoi cell in Voronoi diagram?

share|improve this question
add comment

1 Answer 1

up vote 14 down vote accepted

Look at TileAreas in ComputationalGeometry:

Needs["ComputationalGeometry`"]
boundary = {{0, 0}, {10, 0}, {10, 10}, {0, 10}};
pts = RandomReal[{0, 10}, {100, 2}]
(Print[DiagramPlot[##]]; TileAreas[##]) & @@ 
 Prepend[BoundedDiagram[boundary, pts], pts]
(* {{0.261033,5.7592},{6.21362,4.0213},{4.44609,9.30305},
{7.10641,0.810209},{2.57901,9.65954},{2.34204,1.84401},
{7.76384,0.109391},{2.23168,6.84915},{5.59156,7.56046},{9.12543,8.8625}} *)

(* {6.3428,19.1094,4.97912,9.55327,5.70216,
17.6009,4.37766,10.6483,10.719,10.9674} *)

Simple Voronoi diagram

EDIT: Wait, you wanted perimeters too.

Function[{vert, adj},
  (Total[Norm /@ Subtract @@@ Partition[vert[[#[[2]]]], 2, 1, 1]]) & /@ 
   adj] @@ BoundedDiagram[boundary, pts]
(* {12.8885,17.3528,9.88682,14.4774,10.2263,16.1023,
      10.1097,13.5522,13.3678,14.3459} *)

SECOND EDIT: Number of sides

Length /@ BoundedDiagram[boundary, pts][[2, All, 2]]
(* {4, 6, 5, 5, 5, 6, 3, 6, 4, 5} *)

If you keep reusing the BoundedDiagram of many points, you should probably save it instead of recomputing each time like I'm doing.

share|improve this answer
    
Thank you very much. You are great. I just updated the question and added the number of sides. Sorry about that. Many thanks. –  DeeDee Mar 5 '13 at 1:41
    
once again, many thanks. –  DeeDee Mar 5 '13 at 1:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.