how to distribute users uniformly or non uniformly inside circle

1 回表示 (過去 30 日間)
Ahmad Hani
Ahmad Hani 2018 年 3 月 21 日
編集済み: Jan 2018 年 3 月 21 日
I have a circle with raduis R, how can I distribute users inside this circle in a uniform distribution and after that how can I find the xy coordination of each user inside the circle. thanks

採用された回答

Image Analyst
Image Analyst 2018 年 3 月 21 日

その他の回答 (1 件)

Jan
Jan 2018 年 3 月 21 日
編集済み: Jan 2018 年 3 月 21 日
To get 100 points ("users") inside a circle with radius R with a cheap rejection method
R = 19;
want = 100;
have = 0;
pos = zeros(want, 2);
R2 = R^2;
while have < want
% A random point in [-R, R], 2D:
point = (2 * rand(1, 2) - 1) * R;
% Accept point if inside the circle:
if point(1)^2 + point(2)^2 <= R2
have = have + 1;
pos(have, :) = point;
end
end
A constructive method:
R = 19;
want = 100;
r = sqrt(rand(want, 1)) * R;
alpha = rand(want, 1) * (2 * pi);
pos = [r .* cos(alpha), r .* sin(alpha)];
This is almost correct. The only problem is that rand replies values in the open interval (0,1), but alpha should live on the half open interval [0,1) including the 0. But even then the value 0.0 will occur with the probability of 2^-52 only, such the the difference is tiny.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by