필터 지우기
필터 지우기

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 (최근 30일)
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.

채택된 답변

KSSV
KSSV 2018년 6월 6일
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
RADHIKA GOUR
RADHIKA GOUR 2018년 6월 6일
편집: RADHIKA GOUR 2018년 6월 6일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by