您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > MATLAB动画程序
曲柄滑块机构动画演示hf=figure('name','曲柄滑块机构');set(hf,'color','g');holdonaxis([-6,6,-4,4]);gridonaxis('off');xa0=-5;%活塞左顶点坐标xa1=-2.5;%活塞右顶点坐标xb0=-2.5;%连杆左顶点坐标xb1=2.2;%连杆右顶点坐标x3=3.5;%转轮坐标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','b','linestyle','-','linewidth',40);%设置活塞a3=line(x3,y3,'color',[0.50.60.3],'linestyle','.','markersize',300);%设置转轮a2=line([xb0;xb1],[0;0],'color','black','linewidth',10);%设置连杆a5=line(x5,y5,'color','black','linestyle','.','markersize',40);%设置连杆活塞连接头a4=line(x4,y4,'color','black','linestyle','.','markersize',50);%设置连杆连接头a6=line([xb1;x3],[0;0],'color','black','linestyle','-','linewidth',10);a7=line(x3,0,'color','black','linestyle','.','markersize',50);%设置运动中心a8=line([-5.1;-0.2],[0.7;0.7],'color','y','linestyle','-','linewidth',5);%设置汽缸壁a9=line([-5.1;-0.2],[-0.72;-0.72],'color','y','linestyle','-','linewidth',5);%设置汽缸壁a10=line([-5.1;-5.1],[-0.8;0.75],'color','y','linestyle','-','linewidth',5);%设置汽缸壁a11=fill([-5,-5,-5,-5],[0.61,0.61,-0.61,-0.61],[a,b,c]);%设置汽缸气体len1=4.8;%连杆长len2=2.5;%活塞长r=1.3;%运动半径dt=0.015*pi;t=0;while1t=t+dt;ift2*pit=0;endlena1=sqrt((len1)^2-(r*sin(t))^2);%连杆在运动过程中横轴上的有效长度rr1=r*cos(t);%半径在运动过程中横轴上的有效长度xaa1=x3-sqrt(len1^2-(sin(t)*r)^2)-(r*cos(t));%活塞在运动过程中的右顶点坐标位置xaa0=xaa1-2.5;%%活塞在运动过程中的左顶点坐标位置x55=x3-cos(t)*r;%连杆在运动过程中横坐标位置y55=y3-sin(t)*r;%连杆在运动过程中纵坐标位置set(a4,'xdata',x55,'ydata',y55);%设置连杆顶点运动set(a1,'xdata',[xaa1-2.5;xaa1],'ydata',[0;0]);%设置活塞运动set(a2,'xdata',[xaa1;x55],'ydata',[0;y55]);set(a5,'xdata',xaa1);%设置活塞与连杆连接头的运动set(a6,'xdata',[x55;x3],'ydata',[y55;0]);set(a11,'xdata',[-5,xaa0,xaa0,-5]);%设置气体的填充set(gcf,'doublebuffer','on');%消除震动drawnow;end理想中的弹性振子简谐运动动画演示%Clearrectangle('position',[12,8.5,2,0.3],'FaceColor',[0.5,0.3,0.4]);axis([0,15,-1,10]);%画顶板holdonplot([13,13],[7,8.5],'r','linewidth',2);%画直线y=2:.2:7;M=length(y);x=12+mod(1:M,2)*2;x(1)=13;x(end-3:end)=13;D=plot(x,y);%弹簧C=0:.1:2*pi;r=0.35;t1=r*sin(C);F1=fill(13+r*cos(C),2+t1,'r');%球set(gca,'ytick',[0:2:9]);set(gca,'yticklabels',num2str([-1:3]'));plot([0,15],[3.3,3.3],'black');H1=plot([0,13],[3.3,3.3],'y');%句柄[黄线]Q=plot(0,3.8,'color','r');%运动曲线;td=[];yd=[];T=0;text(2,9,'理想中的弹簧振子简谐振动','fontsize',16);set(gcf,'doublebuffer','on');whileT12;pause(0.2);Dy=(3/2-1/2*sin(pi*T))*1/2;Y=-(y-2)*Dy+7;Yf=Y(end)+t1;td=[td,T];yd=[yd,Y(end)];set(D,'ydata',Y);set(F1,'ydata',Yf,'facecolor',rand(1,3));set(H1,'xdata',[T,13],'ydata',[Y(end),Y(end)]);set(Q,'xdata',td,'ydata',yd);T=T+0.1;end台球模拟程序动画演示资源来自《麓瑜园》axis([-1.6,12.6,-1.6,10.7])%确定坐标轴参数范围holdon%保持当前图形及轴系的所有特性fill([-2,13,13,-2],[-2,-2,11,11],[0,1,0]);%填充底座背景fill([-1,12,12,-1],[-1,-1,10,10],[0,0.5,0]);%填充底座背景ball1=line(0,5,'color','r','marker','.','erasemode','xor','markersize',60);%设置小球颜色,大小,线条的擦拭方式ball2=line(8,9,'color','g','marker','.','erasemode','xor','markersize',60);%设置小球颜色,大小,线条的擦拭方式ball3=line(-1,-1,'color','g','marker','.','erasemode','xor','markersize',80);%设置左下角圆的颜色,大小,线条的擦拭方式ball4=line(12,-1,'color','g','marker','.','erasemode','xor','markersize',80);%设置右下角圆的颜色,大小,线条的擦拭方式ball3=line(-1,10,'color','g','marker','.','erasemode','xor','markersize',80);%设置左上角圆的颜色,大小,线条的擦拭方式ball4=line(12,10,'color','g','marker','.','erasemode','xor','markersize',80);%设置右上角圆的颜色,大小,线条的擦拭方式title('完全非弹碰在模拟台球比赛的应用','color','r','fontsize',15);%图形标题pause(1)%设定暂停时间的长度t=0;dt=0.005;%设制初始数值whilet7.2%设定横轴范围t=t+dt;%设制横轴计算公式y=1/2*t+5;%设制纵轴计算公式set(ball1,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet8.8%设定横轴范围t=t+dt;%设制横轴计算公式y=1/2*t+5;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet11.5%设定横轴范围t=t+dt;%设制横轴计算公式y=-1/2*t+14.3;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet-0.5%设制横轴范围t=t-dt;%设制横轴计算公式y=1/2*t+2.90;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet6%设制横轴范围t=t+dt;%设制横轴计算公式y=-1/2*t+2.40;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet11.5%设制横轴范围t=t+dt;%设制横轴计算公式y=1/2*t-3.0;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束whilet-2%设制横轴范围t=t-dt;%设制横轴计算公式y=-t*7.65/12.9+9.57;%设制纵轴计算公式set(ball2,'xdata',t,'ydata',y)%设制球的运动drawnow;%刷新屏幕end%结束text(2,5,'好!进球了啊!!!恭喜!','fontsize',16,'color','r');%显示字幕的颜色和大小物理中经典模型能量守恒fill([6,7,7,6],[5,5,0,0],[0,0.5,0]);%右边竖条的填充holdon;%保持当前图形及轴系的所有特性fill([2,6,6,2],[3,3,0,0],[0,0.5,0]);%左边竖条的填充holdon;%保持当前图形及轴系的所有特性t1=0:pi/60:pi;plot(4-2*sin(t1-pi/2),5-2*cos(t1-pi/2));%绘制中间的凹弧图形grid;%添加网格线axis([0,9,0,9]);%定义坐标轴的比例%axis('off');%关闭所有轴标注,标记,背景fill([1,2,2,1],[5,5,0,0],[0,0.5,0]);%中间长方形的填充holdon;%保持当前图形及轴系的所有特性title('31608118');%定义图题x0=6;y0=5;head1=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',30);head2=line(x0,y0,'color','r','linestyle','.','erasemode','xor','markersize',50);%设置小球颜色,大小,线条的擦拭方式t=0;%设置小球的初始值dt=0.001;%设置运动周期t1=0;%设置大球的初始值dt1=0.001;while1%条件表达式t=t+dt;x1=9-1*t;y1=5;x3=6;y3=5;ift0x2=6;y2=5;%设置小球的运动轨迹endift2.8t=t+dt;a=sin(t-3);x1=6.1;y1=5.1;x3=4-2*sin(1.5*a);y3=5-2*cos(1.5*a);%设置大球的运动轨迹endset(head1,'xdata',x1,'ydata',y1);%设置球的运动set(head2,'xdata'
本文标题:MATLAB动画程序
链接地址:https://www.777doc.com/doc-3829301 .html