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

后端 未结 5 2022
傲寒
傲寒 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 07:47

    Points on the surface of a sphere can be expressed using two spherical coordinates, theta and phi, with 0 < theta < 2pi and 0 < phi < pi.

    Conversion formula into cartesian x, y, z coordinates:

    x = r * cos(theta) * sin(phi)
    y = r * sin(theta) * sin(phi)
    z = r * cos(phi)
    

    where r is the radius of the sphere.

    So the program could randomly sample theta and phi in their ranges, at uniform distribution, and generate the cartesian coordinates from it.

    But then the points get distributed more densley on the poles of the sphere. In order for points to get uniformly distributed on the sphere surface, phi needs to be chosen as phi = acos(a) where -1 < a < 1 is chosen on an uniform distribution.

    For the Numpy code it would be the same as in Sampling uniformly distributed random points inside a spherical volume , except that the variable radius has a fixed value.

提交回复
热议问题