How can I draw many circles without overlapping?
Ältere Kommentare anzeigen
The following code allows overlapping. How can I draw circles without overlapping?
t = linspace(0,2*pi,100);
figure
cx = 100 + (rand(20, 1) .* 1000); %center
cy = 100 + (rand(20, 1) .* 1000); % center
r = 50; % radius
plot(r*sin(t)+cx,r*cos(t)+cy)
y = r*cos(t)+cy
x = r*sin(t)+cx
for i =0:20
fill(x',y','k')
%fill(r*sin(t)+cx,r*cos(t)+cy, 'k')
r = r+1;
end
i=i+1;
axis([0,1200,0,1200])
axis square
Akzeptierte Antwort
Weitere Antworten (2)
H Y
am 13 Jan. 2018
0 Stimmen
2 Kommentare
michio
am 14 Jan. 2018
I think after the fill function would work out just fine?
Manisha Kumari
am 26 Okt. 2021
Hi ,
in the below code when i am putting axis([0,100,0,100]) then the above code is not working fine. could you please resolve this issue.
clc
close all
clear all
t = linspace(0,2*pi,100);
r = 1; % radius
centers = getCentersWithoutOverlaps(10,2);
cx = centers(:,1);
cy = centers(:,2);
plot(r*sin(t)+cx,r*cos(t)+cy);
y = r*cos(t)+cy;
x = r*sin(t)+cx;
%axis([0,100,0,100])
fill(x',y','r')
axis([0,100,0,100])
Thank you
MFB
am 20 Apr. 2019
0 Stimmen
@michio
you put different radius in function calling i.e. radius 2 in the function as input argument and in the script you put r = 1. Can you explain why???
1 Kommentar
michio
am 22 Apr. 2019
the r=1 in the script is just for visualization purpose. It can be any value. If you set r to be smaller than 2, you can draw circles without overlapping.
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!