Sampling uniformly distributed random points inside a spherical volume

前端 未结 9 645
无人及你
无人及你 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条回答
  •  春和景丽
    2020-11-27 13:33

    Would this be uniform enough for your purposes?

    In []: p= 2* rand(3, 1e4)- 1
    In []: p= p[:, sum(p* p, 0)** .5<= 1]
    In []: p.shape
    Out[]: (3, 5216)
    

    A slice of it

    In []: plot(p[0], p[2], '.')
    

    looks like: enter image description here

提交回复
热议问题