Borrar filtros
Borrar filtros

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 visualización (últimos 30 días)
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.

Respuesta aceptada

KSSV
KSSV el 6 de Jun. de 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 comentario
RADHIKA GOUR
RADHIKA GOUR el 6 de Jun. de 2018
Editada: RADHIKA GOUR el 6 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots 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