MATLAB 数理展示:旋转的错觉

参考视频https://b23.tv/QRQpHi
描述:当小圆半径为大圆一半,且小圆在大圆中做纯滚动运动时,小圆上的各点运动轨迹均为直线,
试验效果
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
完整代码:

function PointOnLineInCircle(N)
if nargin<1||N<3
    N=4;
end
% 0.2157    0.3765    0.5725
% 0.3098    0.5059    0.7412

fig=gcf;
fig.Name='PoLiC';
fig.Position=[50 50 600 600];
fig.NumberTitle='off';
fig.MenuBar='none';

ax=axes(fig);
ax.Position=[0 0 1 1];
ax.XLim=[-2 2];
ax.YLim=[-2 2];
ax.XColor='none';
ax.YColor='none';
hold(ax,'on');
% grid on

thetaB=0;
thetaS=0;



pntsTheta=0:2*pi/N:2*pi;


for i=1:(length(pntsTheta)-1)
    plot([cos(pntsTheta(i)),cos(pntsTheta(i)+pi)].*2,...
         [sin(pntsTheta(i)),sin(pntsTheta(i)+pi)].*2,...
         'Color',[0.8 0.8 0.8],'LineWidth',1.5)
end
if mod(N,2)==0
    for i=1:(length(pntsTheta)-1)
        plot([cos(pntsTheta(i)+2*pi/N/2),cos(pntsTheta(i)+2*pi/N/2+pi)].*2,...
             [sin(pntsTheta(i)+2*pi/N/2),sin(pntsTheta(i)+2*pi/N/2+pi)].*2,...
             'Color',[0.8 0.8 0.8],'LineWidth',1.5)
    end
end


tempT=0:0.1:2*pi+0.1;
CPnts=[cos(tempT);sin(tempT)];
plot(CPnts(1,:).*2,CPnts(2,:).*2,'Color',[0.2098 0.4059 0.6412],'LineWidth',2);

sCircleHdl=plot(cos(thetaB)+CPnts(1,:),sin(thetaB)+CPnts(2,:),...
    'Color',[0.3098 0.5059 0.7412],'LineWidth',2);

pntsHdl=plot(cos(pntsTheta+thetaS)+cos(thetaB),...
    sin(pntsTheta+thetaS)+sin(thetaB),...
    'Color',[0.2157 0.3765 0.5725],'LineWidth',2,'Marker','o',...
    'MarkerFaceColor',[0 0 0],'MarkerEdgeColor',[0 0 0],'MarkerSize',6);

patchHdl=fill(cos(pntsTheta(1:end-1)+thetaS)+cos(thetaB),...
              sin(pntsTheta(1:end-1)+thetaS)+sin(thetaB),...
              [0.8500 0.3250 0.0980],'EdgeColor','none','FaceAlpha',0.1);

while 1
    thetaB=thetaB-2*pi/200;
    thetaS=thetaS+2*pi/200;
    sCircleHdl.XData=cos(thetaB)+CPnts(1,:);
    sCircleHdl.YData=sin(thetaB)+CPnts(2,:);
    pntsHdl.XData=cos(pntsTheta+thetaS)+cos(thetaB);
    pntsHdl.YData=sin(pntsTheta+thetaS)+sin(thetaB);
    patchHdl.XData=cos(pntsTheta(1:end-1)+thetaS)+cos(thetaB);
    patchHdl.YData=sin(pntsTheta(1:end-1)+thetaS)+sin(thetaB);
    pause(0.05);
end


end

猜你喜欢

转载自blog.csdn.net/slandarer/article/details/114037340