# Åsberg

# 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 $i$ should be $i / (numberOfPoints - 1)$ raised to some power $pow$, lets set it to $1$ to begin with. The angle to turn for each dot $i$ should be $2π * i$ times some $turnFraction$. With only this information, you wont be able to easily produce the uniform distribution we seek. If we set the $turnFraction$ to the golden ratio ($\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 $pow$ (the power we raise the distance to) to $0.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.