how to distribute users uniformly or non uniformly inside circle

4 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 21 de Mzo. de 2018

Más respuestas (1)

Jan
Jan el 21 de Mzo. de 2018
Editada: Jan el 21 de Mzo. de 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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by