实例一:椭圆的准圆
可视化效果:
MATLAB 代码:
function directorC
a=3;b=2;syms k
% axes 基础属性设置
ax=gca;
hold on;grid on
ax.XLim=[-6,6];
ax.YLim=[-4,4];
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;
% 绘制圆和椭圆
t=linspace(0,2*pi,200);
plot(a.*cos(t),b.*sin(t),'LineWidth',2.5,'Color',[0,118,168]./255)
plot(sqrt(a^2+b^2).*cos(t),sqrt(a^2+b^2).*sin(t),'LineWidth',2.5,'Color',[169,
64,71]./255)
% 绘制切线和交点
thetaList=linspace(0,2*pi,200);
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;
% 循环绘图
for i=1:length(thetaList)
theta=thetaList(i);
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;
drawnow;
pause(.01)
end
end
实例二:旋转的错觉
可视化效果: