Sampling uniformly distributed random points inside a spherical volume

前端 未结 9 676
无人及你
无人及你 2020-11-27 13:10

I am looking to be able to generate a random uniform sample of particle locations that fall within a spherical volume.

The image below (courtesy of http://nojhan.fre

9条回答
  •  旧时难觅i
    2020-11-27 13:51

    import numpy as np
    import matplotlib.pyplot as plt
    
    
    
    
    
    r= 30.*np.sqrt(np.random.rand(1000))
    #r= 30.*np.random.rand(1000)
    phi = 2. * np.pi * np.random.rand(1000)
    
    
    
    x = r * np.cos(phi)
    y = r * np.sin(phi)
    
    
    plt.figure()
    plt.plot(x,y,'.')
    plt.show()

    this is what you want

提交回复
热议问题