Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Last active April 17, 2018 06:50
Show Gist options
  • Save marmakoide/fe82291687a894de806e628a7b1d7687 to your computer and use it in GitHub Desktop.
Save marmakoide/fe82291687a894de806e628a7b1d7687 to your computer and use it in GitHub Desktop.
Point picking (ie. uniform sampling) of the unit disc (ie. a disc centered at the origin and radius equals to 1)
import numpy
'''
Pick N points uniformly from the unit disc
This sampling algorithm does not use rejection sampling.
'''
def disc_uniform_pick(N):
angle = (2 * numpy.pi) * numpy.random.random(N)
out = numpy.stack([numpy.cos(angle), numpy.sin(angle)], axis = 1)
out *= numpy.sqrt(numpy.random.random(N))[:,None]
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment