登录后复制
function TaiYang_DiQiu_YueLiang_ChangE
clf;cla;clear all;close all;
figure('color','k');
hold on;
axis equal ;
axis off;
set(gcf,'doublebuffer','on');
axis([-70 70 -70 70]);
theta=0:0.01*pi:2*pi;
t=0.005;
R1=42;%设置太阳,地球,月亮,嫦娥之间的距离
R2=20;
R3=6;
W1=5;%设置地球,月亮,嫦娥的角速度
W2=25;
W3=65;
state1=0;state2=0;state3=0;
plot(0,0,'marker','o','markersize',20,'markerfacecolor','r','markeredgecolor','r');%作太阳
X_DiQiu_GuiJi=R1*cos(theta);
Y_DiQiu_GuiJi=R1*sin(theta);
plot(X_DiQiu_GuiJi,Y_DiQiu_GuiJi,'-b','linewidth',2);%作地球轨迹
%做地球,月亮,嫦娥的初始位置
H_DiQiu=plot(R1*cos(state1),R1*sin(state1),'marker','o','markersize',12,'markerfacecolor','b');
%作月亮运动轨迹线
H_YueQiu=plot(R1*cos(state1)+R2*cos(state2),R1*sin(state1)+R2*sin(state2),'marker','o','markersize',8,'markerfacecolor','m','markeredgecolor','m');
xx2=R1*cos(state1)+R2*cos(state2);yy2=R1*sin(state1)+R2*sin(state2);
YueLiang_GuiJi=plot(xx2,yy2,'color','w');
%作嫦娥运动轨迹线
H_ChangE=plot(R1*cos(state1)+R2*cos(state2)+R3*cos(state3),R1*sin(state1)+R2*sin(state2)+R3*sin(state3),'marker','o','markersize',4,'markerfacecolor','c','markeredgecolor','c');
xx3=R1*cos(state1)+R2*cos(state2)+R3*cos(state3);yy3=R1*sin(state1)+R2*sin(state2)+R3*sin(state3);
ChangE_GuiJi=plot(xx3,yy3,'color','m');
%保存GIF文件
f=getframe(gcf);
f=frame2im(f);
[f map]=rgb2ind(f,256);
imwrite(f,map,'ChangE_GuiJi.gif','delaytime',0.1,'loopcount',inf);
for i=1:1.3*length(theta)
x1=R1*cos(state1);y1=R1*sin(state1);
x2=R1*cos(state1)+R2*cos(state2);y2=R1*sin(state1)+R2*sin(state2);
xx2=[xx2 x2];yy2=[yy2 y2];
x3=R1*cos(state1)+R2*cos(state2)+R3*cos(state3);y3=R1*sin(state1)+R2*sin(state2)+R3*sin(state3);
xx3=[xx3 x3];yy3=[yy3 y3];
set(H_DiQiu,'xdata',x1,'ydata',y1) ;
set(H_YueQiu,'xdata',x2,'ydata',y2) ;
set(H_ChangE,'xdata',x3,'ydata',y3) ;
set(YueLiang_GuiJi,'xdata',xx2,'ydata',yy2) ;
set(ChangE_GuiJi,'xdata',xx3,'ydata',yy3) ;
state1=state1+W1*t;
state2=state2+W2*t;
state3=state3+W3*t;
pause(0.1);
drawnow;
%保存GIF文件
f=getframe(gcf);
f=frame2im(f);
[f map]=rgb2ind(f,256);
imwrite(f,map,'ChangE_GuiJi.gif','delaytime',0.1,'writemode','append');
end
1 matlab版本
2014a
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删