how to distribute users uniformly or non uniformly inside circle
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
More Answers (1)
Jan
on 21 Mar 2018
Edited: Jan
on 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.
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!