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.
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!