Instantly share code, notes, and snippets.

Last active May 12, 2018 05:56
Show Gist options
• Save marmakoide/1dbd3d459d41e5caddf8a0400eb0c165 to your computer and use it in GitHub Desktop.
Returns N (approximatively) evenly spread points over the unit sphere

# Golden dot spiral on the sphere

This code sample demonstrates how to generates a set of points that covers a sphere almost evenly, for any number of points. The trick is to use a spiral and the golden angle.

42 points 256 points 999 points

Such points sets are useful for anything that requires sampling a sphere.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy def get_spiral_sphere(n): golden_angle = numpy.pi * (3 - numpy.sqrt(5)) theta = golden_angle * numpy.arange(n) z = numpy.linspace(1. - 1. / n, 1. / n - 1., n) radius = numpy.sqrt(1. - z ** 2) return numpy.stack([radius * numpy.cos(theta), radius * numpy.sin(theta), z], axis = 1)