MATLAB動(dòng)畫匯總_第1頁(yè)
MATLAB動(dòng)畫匯總_第2頁(yè)
MATLAB動(dòng)畫匯總_第3頁(yè)
MATLAB動(dòng)畫匯總_第4頁(yè)
MATLAB動(dòng)畫匯總_第5頁(yè)
已閱讀5頁(yè),還剩56頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、MATLAB 動(dòng)畫演示程序匯總1.彈性蹦球演示程序figure(1);%定義函數(shù)axis(-5.1,5,-0.05,1.05);%繪制二維圖形 hold on;%保持當(dāng)前圖形及軸系所有的特性 axis('off');%覆蓋坐標(biāo)刻度,并填充背景%通過(guò)填充繪出臺(tái)階及兩邊的擋板 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

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、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)%設(shè)置臺(tái)階邊框線,顏色,擦試方式%line(-5,5,0.5,0.5,'color','b','linestyle','-', &

4、#39;markersize',50)%設(shè)置球與地面接 觸面的顏色,擦試方式%line(-5,5,0.75,0.75,'color','b','linestyle','-', 'markersize',50)%設(shè)置球與地面 接觸面的顏色,擦試方式head=line(-5,1,'color','r','linestyle','.','erasemode','xor', 'markersize',60

5、);%設(shè)置 小球顏色,大小,線條和擦試方式%body=line(-5,1,'color','b','linestyle','-','erasemode','none'); %描繪軌跡線%設(shè)置初始條件while 1 t=4; dt=0.001; w=0; dw=0.001;w=0;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t<=4.12 t=dt+t;if w<=1 w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,

6、'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(body,'xdata',t,'ydata',y);%描繪軌跡線drawnow;end %結(jié)束程序w=0;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t>=2.11 t=t-dt;if w<=1 w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(body,'xdata',t,'ydata',y);%描繪軌跡線drawnow;e

7、nd %結(jié)束程序w=0;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t>=1.11 t=t-dt;if w<=1 w=dw+w;elsew=-1;endy=(-w*w)/4+1;set(head,'xdata',t,'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(body,'xdata',t,'ydata',y);%描繪軌跡線drawnow;end %結(jié)束程序w=-0.71;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t>=-0.62 t=t-dt;if w<=1 w=dw+w;elsew=-

8、1;endy=(-w*w)/2+1;set(head,'xdata',t,'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(body,'xdata',t,'ydata',y);%描繪軌跡線drawnow;end %結(jié)束程序w=-0.71;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t>=-2.31 t=t-dt;if w<=1 w=dw+w;elsew=-1;endy=(-w*w)/2+0.75;set(head,'xdata',t,'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(bo

9、dy,'xdata',t,'ydata',y);%描繪軌跡線drawnow;end %結(jié)束程序w=-0.71;%設(shè)置球彈起的初始位置%設(shè)置球彈起的高度while t>=-4 t=t-dt;if w<=1 w=dw+w;elsew=-1;endy=(-w*w)/2+0.5;set(head,'xdata',t,'ydata',y);%設(shè)置球的運(yùn)動(dòng)%set(body,'xdata',t,'ydata',y);%描繪軌跡線drawnow;end %結(jié)束程序for i=0:0.01:200%設(shè)置

10、延時(shí)y=i+2; if(y>199) endend end2.嫦娥奔月演示程序figure('name','嫦娥一號(hào)與月亮、地球關(guān)系');%設(shè)置標(biāo)題名字s1=0:.01:2*pi;hold on;axis equal;%建立坐標(biāo)系axis off% 除掉 Axesr1=10;%月亮到地球的平均距離 r2=3;%嫦娥一號(hào)到月亮的平均距離 w1=1;%設(shè)置月亮公轉(zhuǎn)角速度 w2=12%設(shè)置嫦娥一號(hào)繞月亮公轉(zhuǎn)角速度 t=0;%初始時(shí)刻為 pausetime=.002;%設(shè)置暫停時(shí)間 sita1=0;sita2=0;%設(shè)置開始它們都在水平線上 set(gcf,

11、9;doublebuffer','on') %消除抖動(dòng)plot(-20,18,'color','r','marker','.','markersize',40);text(-17,18,'地球');%對(duì)地球進(jìn)行標(biāo)識(shí)p1=plot(-20,16,'color','b','marker','.','markersize',20);text(-17,16,'月亮');%對(duì)月亮進(jìn)行標(biāo)識(shí)p1

12、=plot(-20,14,'color','w','marker','.','markersize',13); text(-17,14,'嫦娥一號(hào)');%對(duì)嫦娥一號(hào)進(jìn)行標(biāo)識(shí) plot(0,0,'color','r','marker','.','markersize',60);%畫地球 plot(r1*cos(s1),r1*sin(s1);%畫月亮公轉(zhuǎn)軌道 set(gca,'xlim',-20 20,

13、9;ylim',-20 20);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);%畫嫦娥一號(hào)繞月亮 公轉(zhuǎn)軌道p2x=r1*cos(sita1)+r2*cos(sita2);p2y=r1*sin(sita1)+r2*sin(sita2); p2=plot(p2x,p2y

14、,'w','marker','.','markersize',20);%畫嫦娥一號(hào)的初始位置 orbit=line('xdata',p2x,'ydata',p2y,'color','r');%畫嫦娥一號(hào)的運(yùn)動(dòng)軌跡while 1 set(p1,'xdata',r1*cos(sita1),'ydata',r1*sin(sita1);%設(shè)置月亮的運(yùn)動(dòng)過(guò)程 set(l1,'xdata',r1*cos(sita1)+r2*cos(

15、s1),'ydata',r1*sin(sita1)+r2*sin(s1);%設(shè)置 嫦娥一號(hào)繞月亮的公轉(zhuǎn)軌道的運(yùn)動(dòng)過(guò)程 ptempx=r1*cos(sita1)+r2*cos(sita2);ptempy=r1*sin(sita1)+r2*sin(sita2); set(p2,'xdata',ptempx,'ydata',ptempy);%設(shè)置嫦娥一號(hào)的運(yùn)動(dòng)過(guò)程p2x=p2x ptempx;p2y=p2y ptempy; set(orbit,'xdata',p2x,'ydata',p2y);%設(shè)置嫦娥一號(hào)運(yùn)動(dòng)軌跡的顯示

16、過(guò)程 sita1=sita1+w1*pausetime;%月亮相對(duì)地球轉(zhuǎn)過(guò)的角度 sita2=sita2+w2*pausetime;%嫦娥一號(hào)相對(duì)月亮轉(zhuǎn)過(guò)的角度 pause(pausetime); %暫停一會(huì)drawnow end3.曲柄連桿機(jī)構(gòu)充氣球動(dòng)畫演示程序hf=figure('name','打氣筒吹氣球');set(hf,'color','g');axis(-10,10,-4,4);hold onaxis off;%除掉坐標(biāo)xa0=-2.5;%活塞左頂點(diǎn)坐標(biāo) xa1=-1.8;%活塞右頂點(diǎn)坐標(biāo) xb0=-2;%連桿左頂點(diǎn)坐

17、標(biāo) xb1=5;%連桿右頂點(diǎn)坐標(biāo)x3=5.6;%轉(zhuǎn)輪坐標(biāo) y3=0;%轉(zhuǎn)輪坐標(biāo) x4=xb1;%設(shè)置連桿頭的初始位置橫坐標(biāo) y4=0;%設(shè)置連桿頭的初始位置縱坐標(biāo) x5=xa1;y5=0; x6=x3;%設(shè)置連軸初始橫坐標(biāo) y6=0;%設(shè)置連軸初始縱坐標(biāo) a=0.7;b=0.7 c=0.7a1=line(xa0;xa1,0;0,'color','m','linestyle','-','linewidth',20);%設(shè)置活塞a8=line(-2.7;2.3,0.3;0.3,'color','

18、b','linestyle','-','linewidth',5);%設(shè)置打氣筒 a9=line(-2.6;2.3,-0.3;-0.3,'color','b','linestyle','-','linewidth',5);%設(shè)置打氣筒 a10=line(-2.6;-2.6,-0.1;-0.37,'color','b','linestyle','-','linewidth',5);%

19、設(shè)置打氣 筒a11=line(2.0;2.0,0.1;0.37,'color','b','linewidth',5);%設(shè)置打氣筒a12=line(2.0;2.0,-0.1;-0.37,'color','b','linewidth',5);%設(shè)置打氣筒a13=line(-2.6;-2.6,0.1;0.37,'color','b','linestyle','-','linewidth',5);%設(shè)置打氣筒 a14=line

20、(-2.7;-2.7,0.1;-0.1,'color','b','linestyle','-','linewidth',9);%設(shè)置氣筒嘴 a16=line(-3.2;-3.2,0.1;-0.1,'color','r','linestyle','-','linewidth',25);%設(shè)置氣筒嘴 a2=line(xb0;xb1,0;0,'color','m','linewidth',5);

21、%設(shè)置連桿 a5=line(x5,y5,'color','black','linestyle','.','markersize',25);%設(shè)置連桿活塞連接頭 a4=line(x4,y4,'color','black','linestyle','.','markersize',25);%設(shè)置連桿連接頭 a6=line(xb1;x3,0;0,'color','b','linestyle',&

22、#39;-','linewidth',7);%設(shè)置連桿連接軸 a7=line(x3,0,'color','m','linestyle','.','markersize',50);%設(shè)置運(yùn)動(dòng)中心 a3=line(x3,y3,'color' ,0.5 0.6 0.3,'linestyle','.','markersize',85);%設(shè)置手輪 len1=6.8;%連桿長(zhǎng)len2=0.7;%活塞長(zhǎng) r=1.3;%運(yùn)動(dòng)半徑 dd=0.0

23、1;d=-4; plot(d,0,'color','r','marker','.','markersize',10); pausetime=.0001s=0;ds=1;t=0;dt=0.015*pi;while t<=15.68 t=t+dt;drawnow;lena1=sqrt(len1)2-(r*sin(2*t)2);%連桿在運(yùn)動(dòng)過(guò)程中橫軸上的有效長(zhǎng)度rr1=r*cos(t);%半徑在運(yùn)動(dòng)過(guò)程中橫軸上的有效長(zhǎng)度xaa1=x3-sqrt(len12-(sin(2*t)*r)2)-(r*cos(2*t);%活

24、塞在運(yùn)動(dòng)過(guò)程中的右頂 點(diǎn)坐標(biāo)位置xaa0=xaa1-2;%活塞在運(yùn)動(dòng)過(guò)程中的左頂點(diǎn)坐標(biāo)位置 x55=x3-cos(2*t)*r;%連桿在運(yùn)動(dòng)過(guò)程中橫坐標(biāo)位置 y55=y3-sin(2*t)*r*0.32;%連桿在運(yùn)動(dòng)過(guò)程中縱坐標(biāo)位置 set(a4,'xdata',x55,'ydata',y55);%設(shè)置連桿頂點(diǎn)運(yùn)動(dòng)set(a1,'xdata',xaa1-0.2;xaa1,'ydata',0;0);%設(shè)置活塞運(yùn)動(dòng) set(a2,'xdata',xaa1;x55,'ydata',0;y55); set(

25、a5,'xdata',xaa1);%設(shè)置活塞與連桿連接頭的運(yùn)動(dòng) set(a6,'xdata',x55;x3,'ydata',y55;0);if (sign(y55-y3)>0)s=s+ds; d=d-dd; if s>200 s=0; d=0;end set(gcf,'doublebuffer','on');%消除震動(dòng) plot(d,0,'color','r','marker','.','markersize',s);%畫氣

26、球 set(gcf,'doublebuffer','on') %消除抖動(dòng)pause(pausetime); %暫停一會(huì)drawnow;end endx=-8.0 -7.0 -6.0 -5.5 -4.5 -3.5 -3.7 -3 -4 -5.5 -6.5 -7.5 -9.1 -7.3 ;y=-1.8 -1.2 -2.8 -1.5 -2.8 -0.5 -0.7 0.7 0.2 1.5 0.8 1.2 1.9 0.5;fill(x,y,'r');text(-6,0,'pa','fontsize',22);4.打樁機(jī)動(dòng)畫演

27、示程序clear; %清除工作區(qū) clc;%清除命令區(qū) figure('name','武工院打樁機(jī));%設(shè)置標(biāo)題 axis (0 ,10,0,10);%建立坐標(biāo)系hold on;axis off;%除掉坐標(biāo)text(3,9.8,'武工院打樁機(jī)','fontsize',20,'color','r');%畫打樁機(jī)支架c1=line(1;5.5, 0.15;0.15,'color','k','linewidth',8); c2=line(1.7;5.2, 1.5;0

28、.15,'color','k','linewidth',4); c3=line(1.8;5.2, 0.1;8,'color','k','linewidth',4); c4=line(1.7;5.2, 1.5;8,'color','k','linewidth',2); c5=line(1.2;1.8, 0.5;0.5,'color','k','linewidth',13); fill(4.9,5.3,5.3

29、,4.9,8.0,8.0,0.3,0.3,1,0.1,0.5); fill(4.4,4.6,5.6,5.8,5.6,4.6,8.4,8.3,8.3,8.4,8.0,8.0,1,0.1,0.5)%畫打樁機(jī)運(yùn)動(dòng)部分和水泥樁b1=line(8;8,1;6,'color','b','linewidth',6); b2=line(5.5,5.5,7.9,8,'color','k','linewidth',1); b3=line(5.3,5.55,7.9,7.9,'color','k&#

30、39;,'linewidth',3); b4=line(5.5,5.5,7.9,6.3,'color','k','linewidth',3); b5=line(5.5,5.5,7,6.6,'color','k','linewidth',10); b6=line(5.5,5.5,6.6,6.3,'color','k','linewidth',12); pausetime=1.6;%設(shè)置暫停時(shí)間 pause(pausetime);%吊裝水泥

31、樁s=0; ds=0.01; pausetime1=.002;while s<2.5%水泥樁向左移動(dòng)s=s+ds;set(b1,'xdata',8-s;8-s,'ydata',1;6);pause(pausetime1);end pausetime2=1; pause(pausetime2); s=0;ds=0.01;while s<1%水泥樁向下移動(dòng)s=s+ds;set(b1,'xdata',5.5;5.5,'ydata',1-s;6-s);pause(pausetime1);end pause(pausetime2

32、); s=0;ds=0.01;while s<1.3%打樁機(jī)運(yùn)動(dòng)部分下移與水泥樁頂端相接觸s=s+ds; set(b2,'xdata',5.5;5.5,'ydata',7.9-s,8); set(b3,'xdata',5.3;5.55,'ydata',7.9-s,7.9-s);endset(b4,'xdata',5.5;5.5,'ydata',7.9-s,6.3-s); set(b5,'xdata',5.5;5.5,'ydata',7-s,6.6-s); set

33、(b6,'xdata',5.5;5.5,'ydata',6.6-s,6.3-s); pause(pausetime1);%打樁機(jī)開始打樁 pausetime3=.4; pause(pausetime2); s=0;ds=0.06; %設(shè)定打樁進(jìn)度while s<4 a=0; da=0.01;pausetime4=.0002;while a<.4%兩個(gè)子循環(huán)設(shè)置打樁機(jī)鐵鍾上下反復(fù)運(yùn)動(dòng)a=a+da;set(b5,'xdata',5.5;5.5,'ydata',5.7-s+a,5.3-s+a);pause(pausetime

34、4);end a=0;while a<.4 a=a+da;set(b5,'xdata',5.5;5.5,'ydata',6.1-s-a,5.7-s-a);pause(pausetime4);end s=s+ds;%打樁機(jī)運(yùn)動(dòng)部分與水泥樁同時(shí)向下移動(dòng)set(b1,'xdata',5.5;5.5,'ydata',0;5-s); set(b2,'xdata',5.5;5.5,'ydata',6.6-s,8); set(b3,'xdata',5.3;5.55,'ydata

35、9;,6.6-s,6.6-s); set(b4,'xdata',5.5;5.5,'ydata',6.6-s,5-s); set(b5,'xdata',5.5;5.5,'ydata',5.7-s,5.3-s); set(b6,'xdata',5.5;5.5,'ydata',5.3-s,5-s); pause(pausetime3);end5.電路演示程序figure('name','基本電路的模擬');axis(-3,12,0,10);%建立坐標(biāo)系hold on %保持

36、當(dāng)前圖形的所有特性axis('off'); %關(guān)閉所有軸標(biāo)注和控制%下面是畫電池的過(guò)程fill(-1.5,-1.5,1.5,1.5,1,5,5,1,0.5,1,1);%確定坐標(biāo)軸范圍并填充 fill(-0.5,-0.5,0.5,0.5,5,5.5,5.5,5,0,0,0); %確定坐標(biāo)軸范圍并填充 text(-0.5,1.5,'負(fù)極');%在坐標(biāo)上標(biāo)注說(shuō)明文字text(-0.5,3,'電池'); %在坐標(biāo)上標(biāo)注說(shuō)明文字text(-0.5,4.5,'正極'); %在坐標(biāo)上標(biāo)注說(shuō)明文字%下面是畫導(dǎo)電線路的過(guò)程plot(0;0,5.5;

37、6.7,'color','r','linestyle','-','linewidth',4);%繪制二維圖形線豎實(shí)心 紅色plot(0;4,6.7;6.7,'color','r','linestyle','-','linewidth',4); %繪制二維圖形線 實(shí)心紅 色為導(dǎo)線a=line(4;5,6.7;7.7,'color','b','linestyle','-',&#

38、39;linewidth',4,'erasemode','xor');%畫 開關(guān)藍(lán)色plot(5.2;9.2,6.7;6.7,'color','r','linestyle','-','linewidth',4);%繪制圖導(dǎo)線為紅色 plot(9.2;9.2,6.7;3.7,'color','r','linestyle','-','linewidth',4);% 繪制圖導(dǎo)線豎線為 紅線plot(9.

39、2;9.7,3.7;3.7,'color','r','linestyle','-','linewidth',4); % 繪制圖導(dǎo)線橫線為 紅色plot(0;0,1;0,'color','r','linestyle','-','linewidth',4);%如上畫紅色豎線 plot(0;10,0;0,'color','r','linestyle','-','linew

40、idth',4);%如上畫橫線 plot(10;10,0;3,'color','r','linestyle','-','linewidth',4);%畫豎線%下面是畫燈泡的過(guò)程 fill(9.8,10.2,9.7,10.3,3,3,3.3,3.3,0 0 0);%確定填充范圍 plot(9.7,9.7,3.3,4.3,'color','b','linestyle','-','linewidth',0.5);%繪制燈泡外形線為 藍(lán)

41、色plot(10.3,10.3,3.3,4.45,'color','b','linestyle','-','linewidth',0.5); %繪制燈泡外形 線為藍(lán)色%以下為繪圓x=9.7:pi/50:10.3;%繪圓plot(x,4.3+0.1*sin(40*pi*(x-9.7),'color','b','linestyle','-','linewidth',0.5); %繪圓t=0:pi/60:2*pi; %繪圓plot(10+0.

42、7*cos(t),4.3+0.6*sin(t),'color','b'); %繪圓%下面是箭頭及注釋的顯示 text(4.5,10,'電流運(yùn)動(dòng)方向'); %在坐標(biāo)上標(biāo)注說(shuō)明文字 line(4.5;6.6,9.4;9.4,'color','r','linestyle','-','linewidth',4,'erasemode','xor');%繪 制箭頭橫線 line(6.7,9.4,'color','b'

43、,'linestyle','>','erasemode','xor','markersize',10);% %繪制 箭頭三角形pause(1);%下面是開關(guān)閉合的過(guò)程t=0;y=7.7;while y>6.7 %電路總循環(huán)控制開關(guān)動(dòng)作條件 x=4+sqrt(2)*cos(pi/4*(1-t); y=6.7+sqrt(2)*sin(pi/4*(1-t);set(a,'xdata',4;x,'ydata',6.7;y);drawnow;t=t+0.1;end%下面是開關(guān)閉合后

44、模擬大致電流流向的過(guò)程 pause(1); light=line(10,4.3,'color','y','marker','.','markersize',40,'erasemode','xor');%畫燈 絲發(fā)出的光:黃色%畫電流的各部分h=line(1;1,5.2;5.6,'color','r','linestyle','-','linewidth',4,'erasemode',

45、9;xor');g=line(1,5.7,'color','b','linestyle','','erasemode','xor','markersize',10);%給循環(huán)初值t=0; m2=5.7; n=5.7;while n<6.3;%確定電流豎向循環(huán)范圍m=1; n=0.05*t+5.7; set(h,'xdata',m;m,'ydata',n-0.5;n-0.1); set(g,'xdata',m,'yd

46、ata',n);t=t+0.01; drawnow; endt=0;while t<2;%在轉(zhuǎn)角處的停頓時(shí)間 m=1.2-0.2*cos(pi/4)*t); n=6.3+0.2*sin(pi/4)*t);set(h,'xdata',m-0.5;m-0.1,'ydata',n;n);set(g,'xdata',m,'ydata',n);t=t+0.05; drawnow; endt=0;while t<0.5 %在轉(zhuǎn)角后的停頓時(shí)間 t=t+0.5; g=line(1.2,6.5,'color',&

47、#39;b','linestyle','','markersize',10,'erasemode','xor');%繪制第二個(gè)箭頭g=line(1.2,6.5,'color','b','linestyle','>','markersize',10,'erasemode','xor'); %繪 制第二個(gè)箭頭set(g,'xdata',1.2,'ydata',6.

48、5);drawnow; end pause(0.5); t=0;while m<8 % 確定第二個(gè)箭頭的循環(huán)范圍m=1.1+0.05*t; n=6.5; set(g,'xdata',m+0.1,'ydata',6.5);set(h,'xdata',m-0.4;m,'ydata',6.5;6.5);t=t+0.05; drawnow; endt=0;while t<2 %在轉(zhuǎn)角后的停頓時(shí)間 m=8.1+0.2*cos(pi/2-pi/4*t); n=6.3+0.2*sin(pi/2-pi/4*t); set(g,'

49、;xdata',m,'ydata',n); set(h,'xdata',m;m,'ydata',n+0.1;n+0.5); t=t+0.05;drawnow;end t=0;while t<0.5 %在轉(zhuǎn)角后的停頓時(shí)間t=t+0.5;%繪制第三個(gè)箭頭 g=line(8.3,6.3,'color','b','linestyle','>','markersize',10,'erasemode','xor'); g=lin

50、e(8.3,6.3,'color','b','linestyle','v','markersize',10,'erasemode','xor'); set(g,'xdata',8.3,'ydata',6.3);drawnow;endpause(0.5);t=0;while n>1 %確定箭頭的運(yùn)動(dòng)范圍m=8.3;n=6.3-0.05*t; set(g,'xdata',m,'ydata',n); set(h,'

51、;xdata',m;m,'ydata',n+0.1;n+0.5); t=t+0.04;drawnow;end t=0;while t<2%箭頭的起始時(shí)間m=8.1+0.2*cos(pi/4*t); n=1-0.2*sin(pi/4*t); set(g,'xdata',m,'ydata',n); set(h,'xdata',m+0.1;m+0.5,'ydata',n;n); t=t+0.05;drawnow;end t=0;while t<0.5 t=t+0.5;%繪制第四個(gè)箭頭g=line(8.

52、1,0.8,'color','b','linestyle','v','markersize',10,'erasemode','xor'); g=line(8.1,0.8,'color','b','linestyle','<','markersize',10,'erasemode','xor'); set(g,'xdata',8.1,'ydata

53、',0.8);drawnow; end pause(0.5); t=0;while m>1.2 %箭頭的運(yùn)動(dòng)范圍m=8.1-0.05*t; n=0.8; set(g,'xdata',m,'ydata',n);set(h,'xdata',m+0.1;m+0.5,'ydata',n;n);t=t+0.04; drawnow; endt=0;while t<2 %停頓時(shí)間 m=1.2-0.2*sin(pi/4*t); n=1+0.2*cos(pi/4*t); set(g,'xdata',m,'

54、ydata',n);set(h,'xdata',m;m+0.5,'ydata',n-0.1;n-0.5);t=t+0.05; drawnow; endt=0;while t<0.5 %畫第五個(gè)箭頭 t=t+0.5; g=line(1,1,'color','b','linestyle','<','markersize',10,'erasemode','xor'); g=line(1,1,'color','b&#

55、39;,'linestyle','','markersize',10,'erasemode','xor'); set(g,'xdata',1,'ydata',1);drawnow;end t=0;while n<6.3 %循環(huán)范圍m=1; n=1+0.05*t; set(g,'xdata',m,'ydata',n);set(h,'xdata',m;m,'ydata',n-0.5;n-0.1);t=t+0.04; d

56、rawnow; end%下面是開關(guān)斷開后的情況t=0;y=6.7;while y<7.7 %開關(guān)的斷開 x=4+sqrt(2)*cos(pi/4*t); y=6.7+sqrt(2)*sin(pi/4*t); set(a,'xdata',4;x,'ydata',6.7;y); drawnow;t=t+0.1; end pause(0.5);%開關(guān)延時(shí)作用nolight=line(10,4.3,'color','y','marker','.','markersize',40,

57、9;erasemode','xor');end6.電梯動(dòng)畫演示程序figure('name','自控電梯'); axis(-2.0,15.0,-2.0,15.0) hold onfill(-2,15,15,-2,-2,-2,15,15,0.5,0.2,0.3);x1=8 8 10 10; y1=6 0 0 6; x2=10 10 12 12;text(-1,8,'上升','fontsize',10,'color','c');text(4,8,'下降','

58、;fontsize',10,'color','c'); text(6,12.5,'控制電機(jī)','fontsize',10,'color','c'); text(12.5,3,'電梯','fontsize',10,'color','c'); text(5,4.5,'關(guān)閉','fontsize',10,'color','c');text(5,1.5,'打開

59、9;,'fontsize',10,'color','c');l1=line(2;5.5,11;11,'color','c','linestyle','-','linewidth',2); l2=line(2;2,9;11,'color','c','linestyle','-','linewidth',2); l3=line(1;1,7;9,'color','c

60、9;,'linestyle','-','linewidth',2); l4=line(3;3,7;9,'color','c','linestyle','-','linewidth',2); l5=line(1;3,9;9,'color','c','linestyle','-','linewidth',2);%繪制導(dǎo)線 k1=line(2;1,6;7,'color','

61、;r','linestyle','-','linewidth',2);%單刀雙擲開關(guān) k2=line(4;5,3;4,'color','b','linestyle','-','linewidth',2);%單刀雙擲開關(guān) g1=line(7.7;8,3;3,'color','b','linestyle','-','linewidth',2); g2=line(7.7;7.7,3;4,

62、'color','b','linestyle','-','linewidth',2); g3=line(7.4;7.7,2;4,'color','b','linestyle','-','linewidth',2); g4=line(7.4;7.4,2;4,'color','b','linestyle','-','linewidth',2); g5=line(

63、7.1;7.4,2;4,'color','b','linestyle','-','linewidth',2); g6=line(7.1;7.1,2;4,'color','b','linestyle','-','linewidth',2); g7=line(6.8;7.1,2;4,'color','b','linestyle','-','linewidth',

64、2); g8=line(6.8;6.8,2;4,'color','b','linestyle','-','linewidth',2); g9=line(6.5;6.8,2;4,'color','b','linestyle','-','linewidth',2); g10=line(6.5;6.5,2;3,'color','b','linestyle','-','li

65、newidth',2); g11=line(6.0;6.5,3;3,'color','b','linestyle','-','linewidth',2); g12=line(6;6,2;4,'color','c','linestyle','-','linewidth',2); g13=line(5;6,2;2,'color','c','linestyle','-',

66、'linewidth',2); g14=line(5;6,4;4,'color','c','linestyle','-','linewidth',2);%繪制電梯門伸縮控制開關(guān)door1=patch(x1,y1,0 1 1); door2=patch(x2,y1,0 1 1);%畫電梯的兩面門 t=0:pi/100:2*pi; fill(6+0.5*sin(t),11+cos(t),0.7,0.85,0.9);%電機(jī)左端fill(8.5+0.5*sin(t),11+cos(t),0.7,0.85,0

67、.9);%電機(jī)右端 e0=line(9;10,11;11,'color','r','linewidth',2);% e1=line(10;10,6;11,'color','b','linewidth',2);%連接電機(jī)中軸和電梯的線%畫電機(jī)的表面(用八根不同顏色的線代替,每根之間相差 pi/4)%為簡(jiǎn)便起見(jiàn),初始條件下可將八根線分成兩組放在電機(jī)的頂端和底端 s1=line(6;8.5,12;12,'color','c','linestyle','

68、;-','linewidth',2); s2=line(6;8.5,10;10,'color','m','linestyle','-','linewidth',2); s3=line(6;8.5,12;12,'color','b','linestyle','-','linewidth',2); s4=line(6;8.5,10;10,'color','w','linesty

69、le','-','linewidth',2); s5=line(6;8.5,12;12,'color','k','linestyle','-','linewidth',2); s6=line(6;8.5,10;10,'color','g','linestyle','-','linewidth',2); s7=line(6;8.5,12;12,'color','r',

70、'linestyle','-','linewidth',2); s8=line(6;8.5,10;10,'color','b','linestyle','-','linewidth',2);a=0; %設(shè)定電機(jī)運(yùn)轉(zhuǎn)的初始角度 da=0.05;%設(shè)定電機(jī)正轉(zhuǎn)的條件 s=0;%設(shè)定門運(yùn)動(dòng)的初始條件 ds=0.05;%設(shè)定門運(yùn)動(dòng)的周期while s<5%條件表達(dá)式 (當(dāng) 0<s<5 時(shí),電機(jī)正轉(zhuǎn),門上升)a=a+da;xa1=6+abs(0.5*sin(a

71、); %當(dāng)線運(yùn)動(dòng)到電機(jī)背面時(shí)會(huì)覆蓋電機(jī)左端,用 abs 可解 決這一問(wèn)題增強(qiáng)逼真感)xa2=8.5+0.5*sin(a);ya1=11+cos(a);ya2=11+cos(a);%設(shè)定 s1 的兩端點(diǎn)坐標(biāo)(s1 是對(duì)應(yīng) 0 的線)xb1=6+0.5*abs(sin(a+pi); xb2=8.5+0.5*sin(a+pi); yb1=11+cos(a+pi);yb2=11+cos(a+pi); %設(shè)定 s2 的兩端點(diǎn)坐標(biāo)(s2 是對(duì)應(yīng) pi 的線)xc1=6+abs(0.5*sin(a+pi/2); xc2=8.5+0.5*sin(a+pi/2); yc1=11+cos(a+pi/2);yc2=

72、11+cos(a+pi/2);%設(shè)定 s3 的兩端點(diǎn)坐標(biāo)(s3 是對(duì)應(yīng) pi/2 的線)xd1=6+0.5*abs(sin(a-pi/2); xd2=8.5+0.5*sin(a-pi/2); yd1=11+cos(a-pi/2);yd2=11+cos(a-pi/2);%設(shè)定 s4 的兩端點(diǎn)坐標(biāo)(s4 是對(duì)應(yīng)-pi/2 的線)xe1=6+abs(0.5*sin(a+pi/4); xe2=8.5+0.5*sin(a+pi/4); ye1=11+cos(a+pi/4);ye2=11+cos(a+pi/4);%設(shè)定 s5 的兩端點(diǎn)坐標(biāo)(s5 是對(duì)應(yīng) pi/4 的線)xf1=6+0.5*abs(sin(a+pi*3/4); xf2=8.5+0.5*sin(a+pi*3/4); yf1=11+cos(a+pi*3/4);yf2=11+cos(a+pi*3/4);%設(shè)定 s6 的兩端點(diǎn)坐標(biāo)(s6 是對(duì)應(yīng) pi*3/4 的線)xg1=6+abs(0.5*sin(a-pi*3/4); xg2=8.5+0.5*sin(a-3*pi/4); yg1=11+cos(a-3*pi/4);yg2=11+cos(a-3*pi/4);%設(shè)定 s7 的兩端點(diǎn)坐標(biāo)(s7 是對(duì)應(yīng)-3*pi/4 的線)xh1=6+0.5*abs(sin(a-pi/4); xh2=8.

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論