A simple way to generate random points on a sphere

johndcook.com

18 points by piinbinary 2 days ago


jacobolus - 16 hours ago

Here are a few alternatives:

https://observablehq.com/@jrus/stereorandom

At least when trying to end up with stereographically projected coordinates, in general it seems to be faster to uniformly generate a point in the disk by rejection sampling and then transform it by a radially symmetric function to lie on the sphere, rather than uniformly generating a point in the ball and then projecting outward. For one thing, fewer of the points get rejected because the disk fills more of the square than the ball fills of the cube.

arvindh-manian - a day ago

> The advantage of this approach is that it generalizes efficiently to any number of dimensions.

I am unsure about whether this is true. The ratio of a ball’s volume to its enclosing hypercube’s volume should decrease to 0 as dimensionality increases. Thus, the approach should actually generalize very poorly.

egorfine - a day ago

Please forgive me my naivete, but won't generating two random polar coordinates do? I'm bad at math, so I might as well be very very wrong here, but I'd like to know.

Edit: see @srean's excellent explanation why that won't do.

pavel_lishin - a day ago

> First, it’s intuitively plausible that it works.

Maybe; my first instinct is that there'll be some bias somewhere.

Maybe I'll have some time tonight to play with this in p5js.