高分求 追击问题matlab仿真
展开全部
给你一个类似的程序参考,自己运行,慢慢改一下吧
clear;clc;
v0=10;
xw=0;
yw=0.001;
xr=-150;
yr=10;
dt=0.005;
t=0;
figure('units','normalized');
axis([xr 0,0 -xr]);
axis off
set(gcf,'color','w');
w=line(xw,yw,'color','r','marker','.','markersize',20,'erasemode','xor');
r=line(xr,yr,'color','b','marker','.','markersize',10,'erasemode','xor');
wd=line(xw,yw,'color','r','linestyle','-','linewidth',2,'erasemode','none');
rd=line(xr,yr,'color','c','linestyle','-','linewidth',2,'erasemode','none');
while (abs(1-xw/xr)>=1e-5||abs(1-yw/yr)>=1e-5)
yr=v0*t+0.1*t^2;
xr=-150+0.5*t^2;
l=sqrt((xw-xr)^2+(yw-yr)^2);
vx=2*v0*(xr-xw)/l;
vy=2*v0*(yr-yw)/l;
xw=xw+vx*dt;
yw=yw+vy*dt;
set(w,'xdata',xw,'ydata',yw);
set(wd,'xdata',xw,'ydata',yw);
set(r,'xdata',xr,'ydata',yr);
set(rd,'xdata',xr,'ydata',yr);
drawnow;
t=t+dt;
end
hold on
fill([xw-5 xw xw+5 xw+2.5 xw+5 xw xw-5 xw-2.5],[yw-5 yw-2.5 yw-5 yw yw+5 yw+2.5 yw+5 yw],'r');
clear;clc;
v0=10;
xw=0;
yw=0.001;
xr=-150;
yr=10;
dt=0.005;
t=0;
figure('units','normalized');
axis([xr 0,0 -xr]);
axis off
set(gcf,'color','w');
w=line(xw,yw,'color','r','marker','.','markersize',20,'erasemode','xor');
r=line(xr,yr,'color','b','marker','.','markersize',10,'erasemode','xor');
wd=line(xw,yw,'color','r','linestyle','-','linewidth',2,'erasemode','none');
rd=line(xr,yr,'color','c','linestyle','-','linewidth',2,'erasemode','none');
while (abs(1-xw/xr)>=1e-5||abs(1-yw/yr)>=1e-5)
yr=v0*t+0.1*t^2;
xr=-150+0.5*t^2;
l=sqrt((xw-xr)^2+(yw-yr)^2);
vx=2*v0*(xr-xw)/l;
vy=2*v0*(yr-yw)/l;
xw=xw+vx*dt;
yw=yw+vy*dt;
set(w,'xdata',xw,'ydata',yw);
set(wd,'xdata',xw,'ydata',yw);
set(r,'xdata',xr,'ydata',yr);
set(rd,'xdata',xr,'ydata',yr);
drawnow;
t=t+dt;
end
hold on
fill([xw-5 xw xw+5 xw+2.5 xw+5 xw xw-5 xw-2.5],[yw-5 yw-2.5 yw-5 yw yw+5 yw+2.5 yw+5 yw],'r');
更多追问追答
追问
能告诉我一下你这段代码所涉及问题的背景吗
追答
问题的来源就是狼追兔子,主要就是写着玩的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询