% main5.m
global a b m c w
a = 20; b = 15; % semi-axes
m = [10;20];
c = 17.58940018; % constant velocity of jogger
w = 19;  % velocity of dog
y0 = [60, 70, 0]';  % ini. cond., starting point of the dog

options= odeset('AbsTol',1e-5,'Events','on');
[t,Y]= ode23 ('fkt', [0 20], y0, options);
clf; hold on;
axis ([-10 70 -10 70]); 
% axis ('equal');
title ('The Jogger Runs with Constant Velocity.');
p = length(t)-1;
for h=1:p
   plot ([Y(h,1), Y(h+1,1)] , [Y(h,2), Y(h+1,2)], '-', ...
         'Color', 'yellow', 'EraseMode','none');
   s1 = Y(h,3); s2 = Y(h+1,3);
   X1 = m(1) + a*cos(s1); Y1 = m(2) + b*sin(s1);
   X2 = m(1) + a*cos(s2); Y2 = m(2) + b*sin(s2);
   plot ([X1, X2] , [Y1, Y2], ':', ...
         'Color', 'green', 'EraseMode','none');
   drawnow;
end;
cross(Y(p,1),Y(p,2),2);
hold off;

