Matlab 小球绕跑道运动
专栏文章
Matlab 小球绕跑道运动
代码
figure('numbertitle','off','name','Matlab Animation Demo--matlabfan','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('MATLABFAN提醒您:输入参数必须为整数','警告')
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
disp('www.xiexianbin.cn');
return
end
end
end
end
效果

- 上一页: Matlab 常用函数一
- 下一页: 如何在网页中插入关键词
专栏文章
- 牛顿环演示的MATLAB程序
- Matlab 太阳 地球 月亮 绕转演示动画
- Matlab 电影动画(Rotate Peak)
- Matlab 卫星绕地球旋转演示动画
- Matlab 曲柄滑块机构
- Matlab 台球模拟程序 动画演示
- Matlab 小球绕跑道运动(当前)
最近更新
最新评论