Dispersing n points uniformly on a sphere

后端 未结 4 1726
Happy的楠姐
Happy的楠姐 2020-12-15 20:23

I am trying to disperse n points on a sphere such that each point has the \"same\" area \"around\" it. Basically, I\'m trying to integrate a function over a sphere by evalua

4条回答
  •  遥遥无期
    2020-12-15 20:43

    Here's an example algorithm I just whipped up in python:

    from numpy import random, cos, sin, sqrt, pi
    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    
    def rand_sphere(n):
      """n points distributed evenly on the surface of a unit sphere""" 
      z = 2 * random.rand(n) - 1   # uniform in -1, 1
      t = 2 * pi * random.rand(n)   # uniform in 0, 2*pi
      x = sqrt(1 - z**2) * cos(t)
      y = sqrt(1 - z**2) * sin(t)
      return x, y, z
    
    x, y, z = rand_sphere(200)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(x, y, z)
    plt.show()
    

    enter image description here

    Again with 10000 points:

    enter image description here

提交回复
热议问题