Filter löschen
Filter löschen

I want to create a circle of radius 5 and then inside this circle 3 more circles of radius 1 with different centers and then generate random points in each circle separately?please help

1 Ansicht (letzte 30 Tage)
I want to create a circle of radius 5 and then inside this circle 3 more circles with different centers of radius 1 and then generate random points in each circle separately?please help. I need to access the points of each circle separately like user co ordinate in circle 1,2 and 3. User co ordinate of bigger circle should be accessible.

Akzeptierte Antwort

KSSV
KSSV am 6 Jun. 2018
N = 200 ;
R = 5 ;
C = [0 0] ;
th = linspace(0,2*pi,N) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
%
R1 = 1 ;
% get three centers inside the circel
a = -R+R1 ; b = R-R1 ;
x = (b-a).*rand(3,1)+ a;
y = (b-a).*rand(3,1)+ a;
% get each cricle
figure
hold on
plot(xc,yc) ;
plot(x,y,'.r')
cx = zeros(3,N) ;cy = zeros(3,N) ;
for i = 1:3
cx(i,:) = x(i)+R1*cos(th) ;
cy(i,:) = y(i)+R1*sin(th) ;
plot(cx(i,:),cy(i,:),'r')
end
% Generate random numbers inside each circle
M = 100 ;
a = -R1 ; b = R1 ;
rr = cell(3,2) ;
for i = 1:3
rx = x(i)+(b-a).*rand(M,1)+ a;
ry = y(i)+(b-a).*rand(M,1)+ a;
idx = inpolygon(rx,ry,cx(i,:),cy(i,:)) ;
rr{i} = [rx(idx) ry(idx)] ;
plot(rx(idx,:),ry(idx,:),'.','color',rand(1,3))
end
  1 Kommentar
RADHIKA GOUR
RADHIKA GOUR am 6 Jun. 2018
Bearbeitet: RADHIKA GOUR am 6 Jun. 2018
Thank you. This is what I want. But I also want to generate points inside the biggest circle and these points should not go in smaller circles.

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

Community Treasure Hunt

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

Start Hunting!

Translated by