- /
-
Quasi circle of an ellipse
on 21 Nov 2023
- 17
- 26
- 0
- 0
- 1025
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent kpnt thetaList a b k X kline1 kline2 pltHdl
if f==1
a=3;b=2;syms k
% axes基础属性设置
ax=gca;
hold on;grid on
ax.XLim=[-6,6];
ax.YLim=[-6,6];
ax.DataAspectRatio=[1,1,1];
ax.XAxisLocation='origin';
ax.YAxisLocation='origin';
ax.LineWidth=1.5;
ax.XMinorTick='on';
ax.YMinorTick='on';
ax.GridLineStyle='-.';
ax.GridAlpha=.09;
ax.Position=[0,0,1,1];
% 绘制圆和椭圆
t=linspace(0,2*pi,200);
plot(a.*cos(t),b.*sin(t),'LineWidth',2.5,'Color',[0,118,168]./255)
pltHdl=plot(sqrt(a^2+b^2).*cos(0),sqrt(a^2+b^2).*sin(0),'LineWidth',2.5,'Color',[169,64,71]./255);
% 绘制切线和交点
thetaList=linspace(0,2*pi,48);
kline1=plot(0,0,'-.','LineWidth',1.5,'Color',[1,1,1].*.5);
kline2=plot(0,0,'-.','LineWidth',1.5,'Color',[1,1,1].*.5);
kpnt=scatter(a,0,'filled','CData',[1,1,1].*.3);
X=-6:.1:6;
end
% 循环绘图
theta=thetaList(f);
m=sqrt(a^2+b^2).*cos(theta);
n=sqrt(a^2+b^2).*sin(theta);
kk=double(solve((m^2-a^2)*k^2-2*m*n*k+n^2-b^2==0));
Y1=kk(1).*(X-m)+n;Y2=kk(2).*(X-m)+n;
kline1.XData=X;kline1.YData=Y1;
kline2.XData=X;kline2.YData=Y2;
kpnt.XData=m;
kpnt.YData=n;
pltHdl.XData=sqrt(a^2+b^2).*cos(0:.01:theta);
pltHdl.YData=sqrt(a^2+b^2).*sin(0:.01:theta);
end