Challenge: The sphere formation

An interesting challenge in Infinite Fleet development was to generate positions for each flying formations, knowing that the number of spaceships could change (generating positions for a fixed number of allies was not a solution).

Figure 1: Sample of common 2D formations
Figure 1: Sample of common 2D formations

Some were pretty easy to calculate (arrow-shaped formation, line formation…), but one, in particular, was a little bit more difficult: the sphere formation. How to find, in a deterministic way, the positions of N points so they are (almost) evenly distributed on the surface of a sphere?

This problem will have exact solutions only for some specifics numbers of N points, corresponding to the vertices number of regular solids:

Figure 2: Platonic Solids <a href='https://en.wikipedia.org/wiki/Platonic_solid' target='_blank'>https://en.wikipedia.org/wiki/Platonic_solid</a>
Figure 2: Platonic Solids https://en.wikipedia.org/wiki/Platonic_solid

In other cases, the solution can only be an approximation of an evenly distributed set of points on a sphere (but still enough for spaceship’s positions). Many different algorithms exist to solve this issue, but which one fits the most for space formations in a game? Share your solution!

Vector3[] SphereFormationPositions(float sphereRadius, int numberOfShips)
{
    // Share your solution!
}

You have an interesting solution? Please submit it to us and apply for a position at Pixelmatic: challenge@pixelmatic.com!