ACM11 Problem Set 8 Solution

To set up the initial geometry, I chose to have the two uninjured raptors on the x-axis at points (-10,0) and (10,0). A little trig shows the third raptor is at (0,10(Sqrt[3])), and I used Solve to find the position of the human

{hx0, hy0} = {x,y}/.First@Quiet@Solve[Norm[{10,0}-{x,y}] == Norm[{-10,0}-{x,y}]==Norm[{0,10(Sqrt[3])}-{x,y}], {x,y}];
Show[Graphics@{Line[{{-10,0},{10,0}, {0, 10(Sqrt[3])}, {-10,0}}], PointSize[.02],Red, Point/@{{-10,0}, {10,0}, {0, 10(Sqrt[3])}}, Blue, Point[{hx0, hy0}]}, PlotLabel->"Initial Geometry"]

Next we set up the differential equations that govern the motion of the raptors and the human, and their intial positions. Here {hx[t], hy[t]} denotes the position of the human at time t, and {rix[t], riy[t]} denotes the position of the i-th raptor at time t.

d = {Cos[(π/6)], Sin[(π/6)]};
hx[t_] := hx0 + 6t d[[1]]; 
hy[t_] := hy0+6t d[[2]];
r1eqnx = D[r1x[t], t] == 25 ((hx[t]-r1x[t])/(Norm[{hx[t],hy[t]}-{r1x[t], r1y[t]}]));
r1eqny = D[r1y[t], t] == 25 ((hy[t]-r1y[t])/(Norm[{hx[t],hy[t]}-{r1x[t], r1y[t]}]));
r2eqnx =D[r2x[t], t] == 25 ((hx[t]-r2x[t])/(Norm[{hx[t],hy[t]}-{r2x[t], r2y[t]}]));
r2eqny = D[r2y[t], t] == 25 ((hy[t]-r2y[t])/(Norm[{hx[t],hy[t]}-{r2x[t], r2y[t]}]));
r3eqnx =D[r3x[t], t] == 20 ((hx[t]-r3x[t])/(Norm[{hx[t],hy[t]}-{r3x[t], r3y[t]}]));
r3eqny = D[r3y[t], t] == 20((hy[t]-r3y[t])/(Norm[{hx[t],hy[t]}-{r3x[t], r3y[t]}]));
r1xinit = r1x[0] == -10;
r1yinit = r1y[0] == 0;
r2xinit = r2x[0] == 10;
r2yinit = r2y[0] == 0;
r3xinit = r3x[0] == 0;
r3yinit = r3y[0] == 10(Sqrt[3]);

We define the function that will tell Mathematica to stop solving the system of ODEs when a raptor gets close enough to the human.

stopfun[t_] := Min[{Norm[{hx[t], hy[t]} - {r1x[t], r1y[t]}],Norm[{hx[t], hy[t]} - {r2x[t], r2y[t]}],Norm[{hx[t], hy[t]} - {r3x[t], r3y[t]}]}]<.001;

Now we have everything we need to solve for the positions of the raptors up until the time that the human is eaten; we do so, telling Mathematica to stop at the appropriate time using stopfun. If we didn't use stopfun, we'd get a warning message, but the solution returned would be the same. Because we asked Mathematica to solve for r1x, r1y, etc. instead of r1x[t], r1y[t], etc., the result is a list of rules defining anonymous functions which we can evaluate at a time t to determine the raptors' positions.

NDSolve[{r1eqnx, r1eqny, r2eqnx, r2eqny, r3eqnx, r3eqny, r1xinit, r1yinit, r2xinit, r2yinit, r3xinit, r3yinit}, {r1x,r1y,r2x,r2y,r3x,r3y}, {t,0,∞}, Method->{EventLocator, "Event"->stopfun[t]}];
{rx1, rx2, rx3, ry1, ry2, ry3} = {r1x , r2x, r3x, r1y, r2y, r3y}/. First[%];

Finally we plot the positions of the raptors and the human until the human is eaten.

p = ParametricPlot[ {{rx1[t], ry1[t]}, {rx2[t], ry2[t]}, {rx3[t], ry3[t]},{hx[t], hy[t]}}, {t,0,rx1[[1,1,2]]}, Frame->True, Axes->False];
Show[Graphics@{PointSize[.02],Red, Point[{rx1[0], ry1[0]}], Point[{rx2[0], ry2[0]}], Point[{rx3[0], ry3[0]}], Blue, Point[{hx[0], hy[0]}]}, p, Axes->False, Frame->True, PlotLabel->("You are eaten at time " <> ToString[rx1[[1,1,2]]])]