Last active
April 17, 2018 06:50
-
-
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)
This file contains hidden or 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 | |
| ''' | |
| 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