Lloyd´s method (equally spaced points on surface)

I need to put points on a surface equally spaced. Basically give a number N and a surface, and Dynamo has to put the most distributed form possible.

For that, I thought of Lloyd´s method. Basically start with random locations for points, apply Voronoi, then calculate the centroid of the surfaces and apply Voronoi to these new points, until the new and previous centroid are almost the same.

To try, I created a pentagon. I gave my initial points and made a group called iteration. Here we get the Voronoi created, but I need to apply until they are equally spaced following the method. How can I iterate this until the condition mentioned before happens? I would not know how to make this a Python code, but I think it would be the best way. Any ideas for this or other methods?

This is what I made.

This is the idea to follow. Got the image from https://mfkasim91.github.io/2016/12/06/stippling-pictures-with-lloyds-algorithm/

3 Likes

to iterate without python you can use an imperative block or a loop while node with custom node inputs

Have not been able to make it work like that either. How would you suggest creating ir?

Also, I discovered that if I do it manually, it does not work. The first round it works like I showed before, but if I apply the new points nope.