how to distribute users uniformly or non uniformly inside circle

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by