how to distribute users uniformly or non uniformly inside circle

4 vues (au cours des 30 derniers jours)
Ahmad Hani
Ahmad Hani le 21 Mar 2018
Modifié(e) : Jan le 21 Mar 2018
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

Réponse acceptée

Image Analyst
Image Analyst le 21 Mar 2018

Plus de réponses (1)

Jan
Jan le 21 Mar 2018
Modifié(e) : Jan le 21 Mar 2018
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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by