For loop circles that wrap around another circle
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 !
0 commentaires
Réponse acceptée
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)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!