How can we apply Lloyd's relaxation algorithm to a VoronoiMesh
?
Thanks.
UPDATE
Thanks a lot KennyColnago for your answer. Based on Simon Woods suggestion of using PropertyValue[{vmesh, 2}, MeshCellCentroid]
, I think this code can be simplified a bit, e.g.
VoronoiAdaptive2[p_, iter_] := Block[{vmesh = VoronoiMesh[p]},
Do[
vmesh = VoronoiMesh[PropertyValue[{vmesh, 2}, MeshCellCentroid]],
{i, iter}];
vmesh];
Now I have a question about the algorithm itself: According to Wikipedia,
Each time a relaxation step is performed, the points are left in a slightly more even distribution: closely spaced points move farther apart, and widely spaced points move closer together.
But using a large number of iterations with the above code results in a mesh with a concentration of very small cells in the center and large cells on the boundary (omitting the line of KennyColnago's code that excludes cells beyond a certain radius).
For example, with 200 points and the same random seed as KennyColnago and 200 iterations, the following mesh is produced:
SeedRandom[1729];
VoronoiAdaptive2[RandomReal[{-1, 1}, {200, 2}], 200]
Going up to 1200 iterations produces a visually identical image. Is this the expected output? I was hoping to see something more like on this website
VoronoiMesh
to work with, and any progress you have made in solving the problem yourself. Did you try implementing the description of the algorithm in the linked Wikipedia article? $\endgroup$