## Distributing N points on a sphere

In one of my PhD projects, I had the need to distribute *n* points on a sphere of radius *r*. I found a very interesting post in stackoverflow about how to solve the problem and I tested a few of the solutions they proposed by myself. In my opinion, one of the most elegant solutions consists in using a spiral function to distribute the points uniformly. Below you can find a little snippet in Python which uses the spiral method to calculate a list of *n* points (thanks to my colleague Iain for sharing his source code with me):

1 2 3 4 5 6 7 8 9 10 11 12 13 |
def points_on_sphere(number_of_points): """ Creates a list of number_of_points points using the spiral method. """ points = [] increment = math.pi * (3. - math.sqrt(5.)) offset = 2./number_of_points for n in range(number_of_points): y = n * offset - 1.0 + (offset / 2.0) r = math.sqrt(1 - y*y) phi = n * increment points.append([math.cos(phi)*r, y, math.sin(phi)*r]) return points |

This function is based on the original work “*Minimal Discrete Energy on the Sphere*” which you can find online here.

An this is how a sphere of radius 10 with 300 points looks.

## Recent Comments