Random dots to make a circle

3 Ansichten (letzte 30 Tage)
Lucas Sigfridsson
Lucas Sigfridsson am 12 Apr. 2021
Bearbeitet: Alan Stevens am 12 Apr. 2021
This code works excellent to make a circle with randomized dots. My problem now is that I want a inner circle were these randomized dots can't be placed. So it will be like this
but have I drawn a circle.

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 12 Apr. 2021
Try something like
n = 1000;
t = 2*pi*rand(n,1);
Ri = 1;
Ro = 2;
r = Ri + (Ro - Ri)*rand(n,1);
x0 = 0; y0 = 0;
x = x0 + r.*cos(t);
y = y0 + r.*sin(t);
plot(x,y,'.b')
  2 Kommentare
Lucas Sigfridsson
Lucas Sigfridsson am 12 Apr. 2021
Thanks that works excellent. Do you have any ideas how to not have the inner circle in the middle of the bigger one?
Alan Stevens
Alan Stevens am 12 Apr. 2021
Bearbeitet: Alan Stevens am 12 Apr. 2021
How about
n = 2000;
t = 2*pi*rand(n,1);
Ri = 1;
Ro = 3;
r = Ro*rand(n,1);
x0 = 0; y0 = 0;
x = x0 + r.*cos(t);
y = y0 + r.*sin(t);
xoffset = 1;
yoffset = -0.5;
theta = 0:pi/180:2*pi;
xi = xoffset + Ri*cos(theta);
yi = yoffset + Ri*sin(theta);
plot(x,y,'.b')
hold on
fill(xi,yi,'w')
Note that, in order to get a uniform distribution of dots in a circle you need to choose R^2, not R, randomly (though this might not be important for your application, and I've not bothered to do that in the listing here).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by