For loop circles that wrap around another circle

2 vues (au cours des 30 derniers jours)
pauli relanderi
pauli relanderi le 14 Oct 2021
Commenté : pauli relanderi le 15 Oct 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 !

Réponse acceptée

Mitchell Thurston
Mitchell Thurston le 14 Oct 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

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by