相关疑难解决方法(0)

在球形体积内采样均匀分布的随机点

我希望能够生成一个随机均匀的粒子位置样本,该样本落在球形体积内.

下图(http://nojhan.free.fr/metah/提供)显示了我要找的内容.这是穿过球体的切片,显示了点的均匀分布:

均匀分布的圆圈

这就是我目前得到的:

均匀分布但是聚类点

由于球面和笛卡尔坐标之间的转换,您可以看到中心有一组点.

我使用的代码是:

def new_positions_spherical_coordinates(self):
   radius = numpy.random.uniform(0.0,1.0, (self.number_of_particles,1)) 
   theta = numpy.random.uniform(0.,1.,(self.number_of_particles,1))*pi
   phi = numpy.arccos(1-2*numpy.random.uniform(0.0,1.,(self.number_of_particles,1)))
   x = radius * numpy.sin( theta ) * numpy.cos( phi )
   y = radius * numpy.sin( theta ) * numpy.sin( phi )
   z = radius * numpy.cos( theta )
   return (x,y,z)
Run Code Online (Sandbox Code Playgroud)

下面是一些MATLAB代码,据说可以创建一个统一的球形样本,类似于http://nojhan.free.fr/metah给出的等式.我似乎无法破译它或理解他们做了什么.

function X = randsphere(m,n,r)

% This function returns an m by n array, X, in which 
% each of the m rows has the n Cartesian coordinates …
Run Code Online (Sandbox Code Playgroud)

python random matlab geometry uniform-distribution

36
推荐指数
3
解决办法
4万
查看次数

标签 统计

geometry ×1

matlab ×1

python ×1

random ×1

uniform-distribution ×1