matlab动画制作.docx_第1页
matlab动画制作.docx_第2页
matlab动画制作.docx_第3页
matlab动画制作.docx_第4页
matlab动画制作.docx_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

点的简单动画%by dynamic %2008.6.23%t=0:pi/1000:10*pi;x=30*sin(t);y=30*cos(t);z=t;plot3(x,y,z);hold on%axis equalcomet3(x,y,z,0.5)%by dynamic %2008.6.13%vx = 100*cos(1/4*pi);vy = 100*sin(1/4*pi);t = 0:0.001:15;x = vx*t; y = vy*t-9.8*t.2/2;comet(x,y)%by dynamic %2008.6.13%vx = 100*cos(1/4*pi);vy = 100*sin(1/4*pi);t = 0:0.001:15;x = vx*t;y = vy*t-9.8*t.2/2;comet(x,y)%一般的过程%擦除重绘模式动画%选择一个擦除模式set(h,erasemode,erasemode)%h是需要执行动画图像的句柄,一般都是由line或者plot创建%需要执行一些图形计算命令%循环语句中更新坐标数据,一般使用for或者whilefor i=1:n % %必要的MATLAB命令 % set(h,xdata,xdata,ydta,ydata)%更新图像的坐标数据 drownnow%刷新屏幕 % %其它Matlab语句 %End%运动的小球%function f=anim_ball(K,ki)%演示红色小球沿一条封闭旋螺线运动的实时动画% 仅演示实时动画的调用格式为 anim_ball(K)% 既演示实时动画又拍摄照片的调用格式为 f=anim_ball(K,ki)% K 红球运动的循环数(不小于 1 )% ki 指定拍摄照片的瞬间,取 1 到 1034 间的任意整数% f 存储拍摄的照片数据,可用 image(f.cdata) 观察照片% 产生封闭的运动轨线%by dynamic%all rights reserved by %2007.10.26%t1=(0:1000)/1000*10*pi;x1=cos(t1);y1=sin(t1);z1=-t1;t2=(0:10)/10;x2=x1(end)*(1-t2);y2=y1(end)*(1-t2);z2=z1(end)*ones(size(x2);t3=t2;z3=(1-t3)*z1(end);x3=zeros(size(z3);y3=x3;t4=t2;x4=t4;y4=zeros(size(x4);z4=y4;x=x1 x2 x3 x4;y=y1 y2 y3 y4;z=z1 z2 z3 z4;h=figure(numbertitle,off,name,擦除动画演示(运动的小球)Matlabsky);plot3(x,y,z,b)axis off %绘制红点h=line(Color,1 0 0,Marker,.,MarkerSize,40,EraseMode,xor);%擦除模式设为xorn=length(x);i=1;j=1;%循环改变坐标,表现为小球运动while 1 if ishandle(h),return,end set(h,xdata,x(i),ydata,y(i),zdata,z(i); drawnow; pause(0.0005) %这里设置小球运动速度 i=i+1; if nargin=2 & nargout=1 if(i=ki&j=1);f=getframe(gcf);end %获取指定的帧,保存到f中 end if in %判断是否运行了一周,是将i设置为1,并将运行周数j加1 i=1;j=j+1; %判断是否到指定的运行周数,是,退出 if jK;break;end endend%挂摆横梁%by dynamic %2008.6.9%h=figure(numbertitle,on,name,擦除动画演示(挂摆横梁)Matlabsky);%绘制横梁plot(-0.2;0.2,0;0,-k,linewidth,20);%画初始位置的单摆g=0.98;%重力加速度,可以调节摆的摆速l=1;%摆长theta0=pi/4;%初始角度x0=l*sin(theta0);%初始x坐标y0=-l*cos(theta0);%初始y坐标axis(-0.75,0.75,-1.25,0);axis off%创建摆锤head=line(x0,y0,color,r,linestyle,.,erasemode,xor,markersize,40);%擦除模式为xor%创建摆杆body=line(0;x0,-0.05;y0,color,b,linestyle,-,erasemode,xor);%摆的运动t=0;%时间变量dt=0.01;%时间增量while 1 t=t+dt; theta=theta0*cos(sqrt(g/l)*t);%单摆角度与时间的关系 x=l*sin(theta); y=-l*cos(theta); if ishandle(h),return,end set(head,xdata,x,ydata,y);%改变擦除对象的坐标数据 set(body,xdata,0;x,ydata,-0.05;y); drawnow;%刷新屏幕end%将下列命令保存到M文件中,直接运行%Matlab时钟动画演示%rewrite by dynamic%more information please go to try close allhfig=figure(NumberTitle,off,name,Clock Animation Demo-by MatlabSky,MenuBar,none);theta=linspace(0,6.3,1000);x1=8*cos(theta);y1=8*sin(theta);plot(x1,y1,b,linewidth,1.4)%绘制外表盘hold onaxis equalx2=7*cos(theta);y2=7*sin(theta);plot(x2,y2,y,linewidth,3.5)%绘制内表盘fill(0.4*cos(theta),0.4*sin(theta),r);%绘制指针转轴axis off axis(-10 10 -10 10)set(gca,position,0.13 0.05 0.775 0.815)title(date,fontsize,18)for k=1:12;xk=9*cos(-2*pi/12*k+pi/2);yk=9*sin(-2*pi/12*k+pi/2);plot(xk/9*8 xk/9*7,yk/9*8 yk/9*7,color,0.3 0.8 0.9);text(xk,yk,num2str(k),fontsize,16,color,0.9 0.3 0.8,HorizontalAlignment,center);%表盘时刻标度end% 计算时针位置ti=clock;th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;xh3=4.0*cos(th);yh3=4.0*sin(th);xh2=xh3/2+0.5*cos(th-pi/2);yh2=yh3/2+0.5*sin(th-pi/2);xh4=xh3/2-0.5*cos(th-pi/2);yh4=yh3/2-0.5*sin(th-pi/2);hh=fill(0 xh2 xh3 xh4 0,0 yh2 yh3 yh4 0,0.6 0.5 0.3);% 计算分针位置tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;xm3=6.0*cos(tm);ym3=6.0*sin(tm);xm2=xm3/2+0.5*cos(tm-pi/2);ym2=ym3/2+0.5*sin(tm-pi/2);xm4=xm3/2-0.5*cos(tm-pi/2);ym4=ym3/2-0.5*sin(tm-pi/2);hm=fill(0 xm2 xm3 xm4 0,0 ym2 ym3 ym4 0,0.6 0.5 0.3);% 计算秒针位置ts=-(ti(6)/60*2*pi+pi/2;hs=plot(0 7*cos(ts),0 7*sin(ts),color,w,linewidth,2);set(gcf,doublebuffer,on);while 1;ti=clock;%每次读取系统时间,并进行运算% 计算时针位置th=-(ti(4)+ti(5)/60+ti(6)/3600)/12*2*pi+pi/2;xh3=4.0*cos(th);yh3=4.0*sin(th);xh2=xh3/2+0.5*cos(th-pi/2);yh2=yh3/2+0.5*sin(th-pi/2);xh4=xh3/2-0.5*cos(th-pi/2);yh4=yh3/2-0.5*sin(th-pi/2);set(hh,XData,0 xh2 xh3 xh4 0,YData,0 yh2 yh3 yh4 0) % 计算分针位置tm=-(ti(5)+ti(6)/60)/60*2*pi+pi/2;xm3=6.0*cos(tm);ym3=6.0*sin(tm);xm2=xm3/2+0.5*cos(tm-pi/2);ym2=ym3/2+0.5*sin(tm-pi/2);xm4=xm3/2-0.5*cos(tm-pi/2);ym4=ym3/2-0.5*sin(tm-pi/2);set(hm,XData,0 xm2 xm3 xm4 0,YData,0 ym2 ym3 ym4 0)% 计算秒针位置ts=-(ti(6)/60*2*pi+pi/2;set(hs,XData,0 7*cos(ts),YData,0 7*sin(ts)drawnow;pause(0.09)endcatchMatlabSky-打造最优、专业和权威的Matlab技术交流平台!更多信息参见:returnend% %小球绕跑道运动%rewrite by dynamic%more information please go to %figure(numbertitle,off,name,Matlab Animation Demo-by matlabsky,MenuBar,none)prompt=请输入速度v:,请输入长度L:,请输入半径r:;default=5,10,2;v=5;L=10;r=2;p=inputdlg(prompt,输入参数,1,default);v=str2double(p(1);L=str2double(p(2);r=str2double(p(3);if v=0|L=0|r=0 warndlg(Matlabsky提醒您:输入参数必须为整数,警告)else axis(0,2*r+L,0,2*r) ox1=r;oy1=r;ox2=r+L;oy2=r; x1=r:0.015*v:r+L; y1=2*r*ones(size(x1); thita=0:0.015*v/r:pi; x2=sin(thita)*r+ox2; y2=cos(thita)*r+oy2; x3=r+L:-0.015*v:r; y3=zeros(size(x3); x4=-sin(thita)*r+ox1; y4=-cos(thita)*r+oy1; x=x1 x2 x3 x4; y=y1 y2 y3 y4; plot(x,y); text(0,-2,长度L= num2str(L) , 半径r= num2str(r) , 速度v= num2str(v); axis equal set(gca,Visible,off) hm=line(r,2*r,color,red,marker,.,markersize,37,erasemode,xor); while 1 for i=1:length(x) try set(hm,xdata,x(i),ydata,y(i); pause(0.0003) drawnow catch MatlabSky-打造最优、专业和权威的Matlab技术交流平台!更多信息参见: return end end endend%动态绘制椭圆clf;axis(-2,2,-2,2);axis equal;pause(1);h=line(NaN,NaN,marker,o,linesty,-,erasemode,none);t=6*pi*(0:0.02:1);for n=1:length(t) set(h,xdata,2*cos(t(1:n),ydata,sin(t(1:n); pause(0.05);%暂停0.05秒end%卫星绕地球旋转演示动画Matlabsky%by dynamic %2008.12.23%h=figure(numbertitle,off,name,卫星绕地球旋转演示动画Matlabsky);%设置标题名字s1=0:.01:2*pi;hold on;axis equal;%建立坐标系axis off;%除掉Axesr1=10;%地球到太阳的平均距离r2=3;%卫星的轨道半径w1=1;%设置地球公转角速度w2=12;%设置卫星绕地球公转角速度t=0;%初始时刻pausetime=.002;%设置视觉暂留时间sita1=0;sita2=0;%设置开始它们都在水平线上set(gcf,doublebuffer,on) %消除抖动plot(-20,18,color,r,marker,.,markersize,40);text(-17,18,太阳);%对太阳进行标识plot(-20,16,color,b,marker,.,markersize,20);text(-17,16,地球);%对地球进行标识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,-20 20,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);%画卫星绕地球的公转轨道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);%画卫星的运动轨迹while 1 if ishandle(h),return,end set(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=p2x ptempx; p2y=p2y ptempy; set(orbit,xdata,p2x,ydata,p2y);%设置卫星运动轨迹的显示过程 sita1=sita1+w1*pausetime;%地球相对太阳球转过的角度 sita2=sita2+w2*pausetime;%卫星相对地球转过的角度 pause(pausetime); %视觉暂停 drawnow %刷新屏幕,重绘end%擦除动画实例太阳地球月亮卫星,绕转演示动画%by dynamic %2008.12.6%clear; clc;close all%定义几组变量.分别代表的含义是:%相对圆心坐标 半径 最近距离 最远距离 周期 角速度 旋转角度x0=0; y0=0; r0=80; Lmin0=0; Lmax0=0; T0=2160; w0=0*pi/T0; q0=0;x1=0; y1=0; r1=40; Lmin1=25; Lmax1=30; T1=1080; w1=pi/T1; q1=0;x2=0; y2=0; r2=20; Lmin2=8; Lmax2=10; T2=180; w2=pi/T2; q2=0;x3=0; y3=0; r3=10; Lmin3=3; Lmax3=05; T3=30; w3=pi/T3; q3=0;%初始化hh=figure(numbertitle,off,name,太阳地球月亮卫星,绕转演示动画Matlabsky);%设置擦除方式sun=line(0 ,0 ,color,r,linestyle,.,erasemode,xor,markersize,r0); %太阳earth=line(x0,y0,color,k,linestyle,.,erasemode,xor,markersize,r1); %地球moon=line(x1,y1,color,b,linestyle,.,erasemode,xor,markersize,r2); %月亮satellite=line(x2,y2,color,g,linestyle,.,erasemode,norm,markersize,r3); %卫星%添加标注axis offtitle(太阳地球月亮卫星,fontname,宋体,fontsize,9,FontWeight,demi,Color,black); text(-20,50,更多精彩参见);text(-50,50,太阳); %对太阳进行标识line(-55,50,color,r,marker,.,markersize,80);text(-50,40,地球); %对地球进行标识line(-55,40,color,k,marker,.,markersize,40);text(-50,30,月亮); %对月亮进行标识line(-55,30,color,b,marker,.,markersize,20);text(-50,20,卫星); %对卫星进行标识line(-55,20,color,g,marker,.,markersize,10);%绘制轨道s1=0:.01:2*pi;line(Lmax1*cos(s1),Lmin1*sin(s1),linestyle,:); %画地球的轨迹,是个椭圆axis(-60,60,-60,60); %调整坐标轴%开始画图t =0;while 1 if

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论