How do I generate the random number inside the annulus

6 Ansichten (letzte 30 Tage)
Laura
Laura am 27 Sep. 2013
Kommentiert: Ababa Babab am 12 Mai 2020
Hi everyone,
I want to generate 50 particles inside the gap between two circles. The small circle has radius of 5 and the outer circle has radius of 5.12. I want to make sure the particles do not overlap.
Also, can we assign a seed number so the positions of particles will be the same every time i used the same number of seed instead based on clock of computer?
Please helps.
Thanks

Akzeptierte Antwort

Roger Stafford
Roger Stafford am 27 Sep. 2013
Bearbeitet: Roger Stafford am 27 Sep. 2013
% Set your seed here if desired
n = 50;
r1 = 5; r2 = 5.12;
r = sqrt(r1^2+(r2^2-r1^2)*rand(1,n)); % Using square root here ensures distribution uniformity by area
t = 2*pi*rand(1,n);
x = r.*cos(t);
y = r.*sin(t);
plot(x,y,'y.')
axis equal
Note: You worry me where you say "make sure the particles do not overlap". The yellow dots here are assumed to have zero width so they can't overlap.
  2 Kommentare
Image Analyst
Image Analyst am 28 Sep. 2013
I'm always impressed by how clever and creative Roger is. (And Walter too of course).
Ababa Babab
Ababa Babab am 12 Mai 2020
Thank you Roger for this answer, it has helped me.
So, we can consider now that this method is used to implement uniform distribution of users in rings ??
Can you help me with a reference that has stated this method for uniform distribution?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 27 Sep. 2013
What probability function do you want? Equal probability by angle? By radius? By x and y coordinates? By area?
If you were to imagine slitting the annulus at one point, the result would be smoothly deformable to a rectangle. Therefore one way of proceeding would be to generate points on a rectangle and then projecting those coordinates smoothly into the annulus. The most natural transformation of points uniformly randomly generated on a rectangle would result in equal density for radii but not by area. But you didn't say which was important.
If you have a newer MATLAB, see rng() to set the random seed.

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by