For loop circles that wrap around another circle

조회 수: 2 (최근 30일)
pauli relanderi
pauli relanderi 2021년 10월 14일
댓글: pauli relanderi 2021년 10월 15일
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