2

Consider a set of random coordinates.

pts = SortBy[RandomReal[{-1, 1}, {25, 2}], {First, Last}];

and find it's VoronoiMesh,

mesh = VoronoiMesh[pts]

enter image description here

Now for finding faces, we can use mesh["Faces"] to list them base on the coordination of mesh vertices

pts2 = mesh["Coordinates"];

Which for example you can colored them as follows,

col = RandomColor[Length@pts];
Graphics[{{col, Polygon[pts2[[#]]] & /@ mesh["Faces"]}\[Transpose]}]

enter image description here

But I cannot find in mesh["Properties"] any entry related to original vertices, pts. In other words, I want to relate faces (listed in mesh["Faces"] ) to original points (listed in pts) For example, properties "PointInFaces" gives a point in each face, but it is not the original points,

enter image description here

I can use the following code to relate faces to original points, but it is a time-consuming task, particularly when the number of points is large.

VORfaces = Polygon[pts2[[#]]] & /@ mesh["Faces"];
Flatten@Position[# \[Element] VORfaces[[1]] & /@ pts,True] // AbsoluteTiming

Another suggestion is by using PointInFaces and Nearest function.

ff = Nearest[pts -> "Index"]
originalpointIndex =Flatten[ff /@ mesh["PointInFaces"]]

By potting them, you can find an excellent match,

Graphics[{{col, Polygon[pts2[[#]]] & /@ mesh["Faces"]}\[Transpose], Text[#[[1]], #[[2]]] & /@ ({Range[Length@pts], pts}\[Transpose]), White, Text[#[[1]], #[[2]]] & /@ ({originalpointIndex, mesh["PointInFaces"]}\[Transpose]) }]

enter image description here

I am wondering if there are any natural properties to relate mesh coordinate and original vertices?

Rasoul-Ghadimi
  • 681
  • 3
  • 13

0 Answers0