MATLAB动画演示程序汇总1.弹性蹦球演示程序figure(1);%定义函数axis([-5.1,5,-0.05,1.05]);%绘制二维图形holdon;%保持当前图形及轴系所有的特性axis('off');%覆盖坐标刻度,并填充背景%通过填充绘出台阶及两边的挡板fill([4.12,4.22,4.22,4.12],[-0.05,-0.05,1.05,1.05],'y');fill([-5,-3.2,-3.2,-5],[-0.05,-0.05,0,0],'g');fill([-3.2,-2.8,-2.8,-3.2],[-0.05,-0.05,0.2,0.2],'g');fill([-3.2,-1.4,-1.4,-3.2],[0.2,0.2,0.25,0.25],'g');fill([-1.4,-1,-1,-1.4],[0.2,0.2,0.45,0.45],'g');fill([-1.4,0.4,0.4,-1.4],[0.45,0.45,0.5,0.5],'g');fill([0.4,0.8,0.8,0.4],[0.45,0.45,0.7,0.7],'g');fill([0.4,2.0,2.0,0.4],[0.7,0.7,0.75,0.75],'g');fill([2.0,2.3,2.3,2.0],[-0.05,-0.05,0.75,0.75],'g');fill([2.3,4.12,4.12,2.3],[-0.05,-0.05,0,0],'g');%x2=line([-5,5],[0.25,0.25],'color','g','linestyle','-','markersize',50)%设置台阶边框线,颜色,擦试方式%line([-5,5],[0.5,0.5],'color','b','linestyle','-','markersize',50)%设置球与地面接触面的颜色,擦试方式%line([-5,5],[0.75,0.75],'color','b','linestyle','-','markersize',50)%设置球与地面接触面的颜色,擦试方式head=line(-5,1,'color','r','linestyle','.','erasemode','xor','markersize',60);%设置小球颜色,大小,线条和擦试方式%body=line(-5,1,'color','b','linestyle','-','erasemode','none');%描绘轨迹线%设置初始条件while1t=4;dt=0.001;w=0;dw=0.001;w=0;%设置球弹起的初始位置%设置球弹起的高度whilet=4.12t=dt+t;ifw=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=0;%设置球弹起的初始位置%设置球弹起的高度whilet=2.11t=t-dt;ifw=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=0;%设置球弹起的初始位置%设置球弹起的高度whilet=1.11t=t-dt;ifw=1w=dw+w;elsew=-1;endy=(-w*w)/4+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet=-0.62t=t-dt;ifw=1w=dw+w;elsew=-1;endy=(-w*w)/2+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet=-2.31t=t-dt;ifw=1w=dw+w;elsew=-1;endy=(-w*w)/2+0.75;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet=-4t=t-dt;ifw=1w=dw+w;elsew=-1;endy=(-w*w)/2+0.5;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序fori=0:0.01:200%设置延时y=i+2;if(y199)endendend2.嫦娥奔月演示程序figure('name','嫦娥一号与月亮、地球关系');%设置标题名字s1=[0:.01:2*pi];holdon;axisequal;%建立坐标系axisoff%除掉Axesr1=10;%月亮到地球的平均距离r2=3;%嫦娥一号到月亮的平均距离w1=1;%设置月亮公转角速度w2=12%设置嫦娥一号绕月亮公转角速度t=0;%初始时刻为0pausetime=.002;%设置暂停时间sita1=0;sita2=0;%设置开始它们都在水平线上set(gcf,'doublebuffer','on')%消除抖动plot(-20,18,'color','r','marker','.','markersize',40);text(-17,18,'地球');%对地球进行标识p1=plot(-20,16,'color','b','marker','.','markersize',20);text(-17,16,'月亮');%对月亮进行标识p1=plot(-20,14,'color','w','marker','.','markersize',13);text(-17,14,'嫦娥一号');%对嫦娥一号进行标识plot(0,0,'color','r','marker','.','markersize',60);%画地球plot(r1*cos(s1),r1*sin(s1));%画月亮公转轨道set(gca,'xlim',[-2020],'ylim',[-2020]);p1=plot(r1*cos(sita1),r1*sin(sita1),'color','b','marker','.','markersize',30);%画月亮初始位置l1=plot(r1*cos(sita1)+r2*cos(s1),r1*sin(sita1)+r2*sin(s1));%画嫦娥一号绕月亮公转轨道p2x=r1*cos(sita1)+r2*cos(sita2);p2y=r1*sin(sita1)+r2*sin(sita2);p2=plot(p2x,p2y,'w','marker','.','markersize',20);%画嫦娥一号的初始位置orbit=line('xdata',p2x,'ydata',p2y,'color','r');%画嫦娥一号的运动轨迹while1set(p1,'xdata',r1*cos(sita1),'ydata',r1*sin(sita1));%设置月亮的运动过程set(l1,'xdata',r1*cos(sita1)+r2*cos(s1),'ydata',r1*sin(sita1)+r2*sin(s1));%设置嫦娥一号绕月亮的公转轨道的运动过程ptempx=r1*cos(sita1)+r2*cos(sita2);ptempy=r1*sin(sita1)+r2*sin(sita2);set(p2,'xdata',ptempx,'ydata',ptempy);%设置嫦娥一号的运动过程p2x=[p2xptempx];p2y=[p2yptempy];set(orbit,'xdata',p2x,'ydata',p2y);%设置嫦娥一号运动轨迹的显示过程sita1=sita1+w1*pausetime;%月亮相对地球转过的角度sita2=sita2+w2*pausetime;%嫦娥一号相对月亮转过的角度pause(pausetime);%暂停一会drawnowend3.曲柄连杆机构充气球动画演示程序hf=figure('name','打气筒吹气球');set(hf,'color','g');axis([-10,10,-4,4]);holdonaxisoff;%除掉坐标xa0=-2.5;%活塞左顶点坐标xa1=-1.8;%活塞右顶点坐标xb0=-2;%连杆左顶点坐标xb1=5;%连杆右顶点坐标x3=5.6;%转轮坐标y3=0;%转轮坐标x4=xb1;%设置连杆头的初始位置横坐标y4=0;%设置连杆头的初始位置纵坐标x5=xa1;y5=0;x6=x3;%设置连轴初始横坐标y6=0;%设置连轴初始纵坐标a=0.7;b=0.7c=0.7a1=line([xa0;xa1],[0;0],'color','m','linestyle','-','linewidth',20);%设置活塞a8=line([-2.7;2.3],[0.3;0.3],'color','b','linestyle','-','linewidth',5);%设置打气筒a9=line([-2.6;2.3],[-0.3;-0.3],'color','b','linestyle','-','linewidth',5);%设置打气筒a10=line([-2.6;-2.6],[-0.1;-0.37],'color','b','linestyle','-','linewidth',5);%设置打气筒a11=line([2.0;2.0],[0.1;0.37],'color','b','linewidth',5);%设置打气筒a12=line([2.0;2.0],[-0.1;-0.37],'color','b','linewidth',5);%设置打气筒a13=line([-2.6;-2.6],[0.1;0.37],'color','b','linestyle','-','linewidth',5);%设置打气筒a14=line([-2.7;-2.7],[0.1;-0.1],'color','b','linestyle','-','linewidth',9);%设置气筒嘴a16=line([-3.2;-3.2],[0.1;-0.1],'color','r','linestyle','-','linewidth',25);%设置气筒嘴a2=line([xb0;xb1],[0;0],'color','m','linewidth',5);%设置连杆a5=line(x5,y5,'color','black','linestyle','.','markersize',25);%设置连杆活塞连接头a4=line(x4,y4,'color','black','linestyle','.','markersize',25);%设置连杆连接头a6=line([xb1;x3],[0;0],'color','b','linestyle','-','linewidth',7);%设置连杆连接轴a7=line(x3,0,'color','m','linestyle','.','markersize',50);%设置运动中心a3=line(x3,y3,'color',[0.50.60.3],'linestyle