Message Boards Message Boards

Create charts or animation of a Pursuit Curve?

Posted 7 years ago

I want to try create charts or animation Pursuit Curve. I coped code from this file but it doesn't work. I have no idea why.

http://mathworld.wolfram.com/PursuitCurve.html

Unit[l_] := l/Sqrt[l.l]

PursuitCurve[a_, p0_, {t_, t0_, t1_, dt_}, r_: 1., opts___] := Module[
  {
   soln, curve,
   x, y, f
   },
  soln = NDSolve[{
     Unit[a - {x[t], y[t]}].{x'[t], y'[t]} == 1,
     x'[t]^2 + y'[t]^2 == 1,
     x[0] == p0[[1]],
     y[0] == p0[[2]]
     }, {x[t], y[t]}, {t, t0, t1}];
  targetpath = ParametricPlot[a, {t, t0, t1},
     DisplayFunction -> Identity][[1]];
  curve = ParametricPlot[Evaluate[{x[t], y[t]} /. soln], {t, t0, t1},
     PlotRange -> All, AspectRatio -> Automatic,
     DisplayFunction -> Identity,
     PlotStyle -> Red][[1]];
  d = D[a, t];
  movie = Show /@ Table[Graphics[{
       Arrow[a, a + r d],
       {Thickness[.02], targetpath},
       {Dashing[{1, 1} .02], Blue,
        Line[{pt = {x[t], y[t]} /. soln[[1]], a}]
        },
       {Red, curve},
       {PointSize[.08], Point[a]},
       {Blue, Arrow[pt, pt + r Unit[a - pt]]},
       {Red, PointSize[.05], Point[pt]}
       },
      opts,
      AspectRatio -> Automatic],
     {t, t0, t1, dt}]
  ]

PursuitCurve[{0, t}, {1, -1}, {t, 0, 2, .05}, .2, 
 PlotRange -> {{-.1, 1.1}, {-1.1, 2.1}}]
Attachments:
POSTED BY: pawel kowalski
4 Replies

The syntax for Arrow has changed. Try with this:

Unit[l_] := l/Sqrt[l.l]
PursuitCurve[a_, p0_, {t_, t0_, t1_, dt_}, r_: 1., opts___] := 
  Module[{soln, curve, x, y, f, targetpath, d}, 
   soln = NDSolve[{Unit[a - {x[t], y[t]}].{x'[t], y'[t]} == 1, 
      x'[t]^2 + y'[t]^2 == 1, x[0] == p0[[1]], 
      y[0] == p0[[2]]}, {x[t], y[t]}, {t, t0, t1}];
   targetpath = ParametricPlot[a, {t, t0, t1}][[1]]; 
   curve = ParametricPlot[Evaluate[{x[t], y[t]} /. soln], {t, t0, t1},
       PlotRange -> All, AspectRatio -> Automatic, 
      PlotStyle -> Red][[1]]; d = D[a, t];
   movie = 
    ListAnimate[
     Table[Graphics[{Arrow[{a, a + r d}], {Thickness[.02], 
         targetpath}, {Dashing[{1, 1} .02], Blue, 
         Line[{pt = {x[t], y[t]} /. soln[[1]], a}]}, {Red, 
         curve}, {PointSize[.08], Point[a]}, {Blue, 
         Arrow[{pt, pt + r Unit[a - pt]}]}, {Red, PointSize[.05], 
         Point[pt]}}, opts, AspectRatio -> Automatic], {t, t0, t1, 
       dt}]]];

PursuitCurve[{0, t}, {1, -1}, {t, 0, 2, .05}, .2, 
 PlotRange -> {{-.1, 1.1}, {-1.1, 2.1}}]
POSTED BY: Gianluca Gorni
Posted 7 years ago

Thank you very much. It works!

POSTED BY: pawel kowalski

Please use the following code form the demonstration Pursuit Curves by @Michael Trott:

enter image description here

pursuitGraphics[{x0_,y0_},T_,v_,?_]:=
Module[{},
X[t_]=(1-? t) Cos[t];
Y[t_]=(1-? t) Sin[t];
nds=NDSolve[{Thread[{
    x'[t],y'[t]}==v {X[t]-x[t],
    Y[t]-y[t]}/Sqrt[(X[t]-x[t])^2+(Y[t]-y[t])^2]],
    x[0]==x0,y[0]==y0},{x,y},{t,0,T},
    PrecisionGoal->4,
    StoppingTest:>((X[t]-x[t])^2+(Y[t]-y[t])^2<10^-3)];
tm=nds[[1,1,2,1,1,2]];
Show[{
ParametricPlot[Evaluate[{X[t],Y[t]}],{t,0,tm},
    PlotStyle->{{Thickness[0.002],Black}}, PlotRange -> All,MaxRecursion->ControlActive[2,6]],
ParametricPlot[Evaluate[{x[t],y[t]}/.nds[[1]]],{t,0,tm},
    PlotStyle->{Thickness[0.005]},
    ColorFunction->(Blend[{RGBColor[.8,1,0],RGBColor[1,.8,0],RGBColor[0,.75,0.02],RGBColor[0,.5,1]},#3]&),
    PlotRange->All,MaxRecursion->ControlActive[2,6]]}, PlotRange -> 2,
Frame->False,Axes->False,FrameTicks->None,ImageSize->{400,400}]]

Manipulate[
pursuitGraphics[xy0, T,v, ?] ,
{{T,40,"maximal running time of the predator"},1, 100},
{{v, 0.894,"predator speed"},0, 2},
{{?,0.01,"prey spiral contraction speed"},-1, 1},
{{xy0,{-1.03, -0.21},"initial position predator"},{-2,-2},{2,2}},
ControlPlacement->{Top,Top,Top,Left},SaveDefinitions->True]
POSTED BY: Vitaliy Kaurov
Posted 7 years ago

Thank you very much. It works!

POSTED BY: pawel kowalski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract