Generate a random sample of points distributed on the surface of a unit sphere

后端 未结 5 2027
傲寒
傲寒 2020-12-05 07:18

I am trying to generate random points on the surface of the sphere using numpy. I have reviewed the post that explains uniform distribution here. However, need ideas on how

5条回答
  •  甜味超标
    2020-12-05 08:01

    (edited to reflect corrections from comments)

    i investigated a few constant time approaches to this problem in 2004.

    assuming you're working in spherical coordinates where theta is the angle around the vertical axis (eg longitude) and phi is the angle raised up from the equator (eg latitude), then to obtain a uniform distribution of random points on the hemisphere north of the equator you do this:

    1. choose theta = rand(0, 360).
    2. choose phi = 90 * (1 - sqrt(rand(0, 1))).

    to get points on a sphere instead of a hemisphere, then simply negate phi 50% of the time.

    for the curious, a similar approach holds for generating uniformly-distributed points on a unit-disk:

    1. choose theta = rand(0, 360).
    2. choose radius = sqrt(rand(0, 1)).

    i do not have proofs for the correctness of these approaches, but i've used them with lots of success over the past decade or so, and am convinced of their correctness.

    some illustration (from 2004) of the various approaches is here, including a visualization of the approach of choosing points on the surface of a cube and normalizing them onto the sphere.

提交回复
热议问题