Sunflower Pattern

I recently needed a way of uniformly distributing a set of points inside a circle. When I thought about this I remembered having watched Sebastian Lague’s video about boids. In it he discusses uniformly distributing points on a sphere and takes the route via points in a circle, exactly my problem.

In his video, Lauge plays with the distribution of these dots for a while in what looks like a nice little interactive tool. So, getting as side tracked as he did, I created my rendition of that tool. With that, I too could play with the dots a bit before returning to my original task. Try it out yourself!

Simplified, the algorithm behind this works out to: begin in the center, with increasing distance place dots in a spiral rotating some angle for each dot. Now, the full version of this algorithm is that the distance from the center for each dot ii should be i/(numberOfPoints1)i / (numberOfPoints - 1) raised to some power powpow, lets set it to 11 to begin with. The angle to turn for each dot ii should be 2πi2π * i times some turnFractionturnFraction. With only this information, you wont be able to easily produce the uniform distribution we seek. If we set the turnFractionturnFraction to the golden ratio (1.618\sim1.618), the most irrational number, we magickly get a sunflower pattern. This also happens to be the number we need to uniformly distribute the dots, but we also need to set powpow (the power we raise the distance to) to 0.50.5, effectively taking the square root. You can read more about the theory from this Stackoverflow.com answer.

As for how I created my interactive tool: I used React, something I’ve only recently been a fan of but now am a big fan of; my own UI frame work Syngg; and some spaghetti code. Nonetheless, you can find the source on my GitHub.