For loop circles that wrap around another circle

6 Ansichten (letzte 30 Tage)
pauli relanderi
pauli relanderi am 14 Okt. 2021
Kommentiert: pauli relanderi am 15 Okt. 2021
So my problem is that i need to plot circles that wrap around another circle.
The calculations calculate the R(inner circles radius) based on n(the number of circles that wrap around it and r which is always 1)
something like this :
i need to make an for loop k=1:n, that plots the small circles around the red inner circle.
ive tried everything and cant seem to get it right.
here is the base calculation ive gotten so far.
r=1 % small circles radius
n=17 %number of small crircles
alfa=180./n %angle
x0=0,y0=0%circle center points
R=((1-sind(alfa))/sind(alfa))*r %calculating the R(radius of red inner circle)
%innercircle coords
t=0:360;
xymp=+R.*cosd(t);
yymp=y0+R.*sind(t);
%outer circle coords
t=0:360;
Syy=+(R+(r.*2))*cosd(t);
Syx=y0+(R+(r.*2))*sind(t);
plot(xymp,yymp,'r','linewidth',2)%inner circle
hold
plot(Syx,Syy,'b','linewidth',2) %outer circle
this is the for loop ive tried,
for k=1:n
s=0:alfa:360
x=x0+(R+r).*cosd(s)
y=y0+(R+r).*sind(s)
xy=x+r.*cosd(s);
yy=y+r.*sind(s);
plot(x,y)
end
i know its not pretty
Thanks for any help !

Akzeptierte Antwort

Mitchell Thurston
Mitchell Thurston am 14 Okt. 2021
Modified the calculation of alfa, R, and a slight change with the for loop
clear;
r=1; % small circles radius
n=17; %number of small crircles
alfa=180-(180*(n-2))/n; %angle
x0=0;y0=0;%circle center points
R=r*(1/(sind(180/n)) -1); %calculating the R(radius of red inner circle)
%innercircle coords
t=0:360;
xymp=x0+R.*cosd(t);
yymp=y0+R.*sind(t);
%outer circle coords
t=0:360;
Syy=+(R+(r.*2))*cosd(t);
Syx=y0+(R+(r.*2))*sind(t);
plot(xymp,yymp,'r','linewidth',2)%inner circle
hold on
plot(Syx,Syy,'b','linewidth',2) %outer circle
s=0:alfa:360;
for k=1:n
x=x0+(R+r).*cosd(s(k));
y=y0+(R+r).*sind(s(k));
xy=x+r.*cosd(t);
yy=y+r.*sind(t);
plot(xy,yy,'-k')
end
hold off

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by