求MATLAB CODE 提示:Three Ants in Pursuit:Consider three ants sitting at the vertices of an equilateral triangle whose sides are each 1 km long.The ants begin walking at the same time at speed s km per hour along a path towards the ant on their r
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 22:47:57
求MATLAB CODE 提示:Three Ants in Pursuit:Consider three ants sitting at the vertices of an equilateral triangle whose sides are each 1 km long.The ants begin walking at the same time at speed s km per hour along a path towards the ant on their r
求MATLAB CODE 提示:
Three Ants in Pursuit:Consider three ants sitting at the vertices of an equilateral triangle whose sides are each 1 km long.The ants begin walking at the same time at speed s km per hour along a path towards the ant on their right.We are interested in plotting the path along which each ant walks.In order to simulate the ants' movement,consider their path as a sequence of straight-line paths taken over small time steps of length Δt.At the start of each time step,the direction of each ant is calculated,and the ant is advanced a distance of sΔt along that path.Repeat.
求MATLAB CODE 提示:Three Ants in Pursuit:Consider three ants sitting at the vertices of an equilateral triangle whose sides are each 1 km long.The ants begin walking at the same time at speed s km per hour along a path towards the ant on their r
clear;clc;close all;
x=[0 1 0.5];
y=[0 0 sqrt(3)/2];
d=1e-3;
figure
hold on
plot([x 0],[y 0],'black');
while (x(1)-x(3))^2+(y(1)-y(3))^2>d^2
m=[x(2:3) x(1)];n=[y(2:3) y(1)];
a=m-x;b=n-y;
x0=x+a*d;y0=y+b*d;
plot([x;x0],[y;y0]);
x=x0;y=y0;
end