For loop circles that wrap around another circle

2 次查看(过去 30 天)
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 !

采纳的回答

Mitchell Thurston
Mitchell Thurston 2021-10-14
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by