Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Last active May 2, 2023 03:27
Show Gist options
  • Save marmakoide/79427f68bcbba768456011c050328292 to your computer and use it in GitHub Desktop.
Save marmakoide/79427f68bcbba768456011c050328292 to your computer and use it in GitHub Desktop.
Returns N (approximatively) evenly spread points over the unit disc (aka. Vogel's method)

Golden dot spiral on the disc

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

42 points 256 points 999 points
dot spiral, 42 points dot spiral, 256 points dot spiral, 999 points

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

import numpy
def get_spiral_disc(n):
golden_angle = numpy.pi * (3 - numpy.sqrt(5))
theta = golden_angle * numpy.arange(n)
radius = numpy.sqrt(numpy.arange(n) / float(n))
return radius[:,None] * numpy.stack([numpy.cos(theta), numpy.sin(theta)], axis = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment