2017-10-19 92 views
3

我試圖通過使用在原產地中心下面的命令來產生內球隨機點通過使用下面的代碼如何使用MATLAB

no_of_spots = 3000 
radius=20 
rvals = (2)*rand(no_of_spots,1)-(1); 
elevation = asin(rvals); 
azimuth = 2*pi*rand(no_of_spots,1); 
radii = rand(no_of_spots,1)*radius; 
[point_x,point_y,point_z] = sph2cart(azimuth,elevation,radii); 

我得到的結果sphere with random points

從圖生成內球隨機點它是隨機點集中在原點附近,即看起來像高斯分佈。我需要在球體內均勻分佈的隨機點,或者需要將點的集中從中心轉移到另一個點。我怎樣才能做到這一點/誰能幫助提前/ 感謝, 馬努

+0

[在球形體積內採樣均勻分佈的隨機點]可能的重複(https://stackoverflow.com/questions/5408276/sampling-uniformly-distributed-random-points-inside-a-spherical-volume) – buzjwa

回答

4

如果你調整你的radii專線:

radii = rand(no_of_spots,1)*radius; 

要:

radii = (rand(no_of_spots,1).^(1/3))*radius; 

你應該得到更多的統一的分佈。

這是Knuth在中描述的計算機編程藝術。卷。 2,並且標記爲here

+1

謝謝你的回覆 – manoos