clear
close all

disp('                      CURVATURE                       ')

disp(' ')
disp('  The  "kissing" circle at several points on the parabolic curve ')
disp(' t -> (t, .5*t^2 ) ')
clear s t; clf

t = linspace(-4,4, 201);
plot(t, .5*t.^2)
hold on
axis([-5,5, -2, 6])
tau = linspace( 0, 2*pi, 101);
pause

for j = -2:2
  s = j;
  rho = (1+s^2)^1.5;
  kappa = 1/rho
  p = [s, .5*s^2] + rho*[-s,1]/sqrt(s^2+1);
  if j <= 0
      color = 'r';
  else
      color = 'g';
  end
  plot(s, .5*s^2, '*')
  
  plot(p(1) + rho*cos(tau), p(2) +rho*sin(tau),color)
  axis([-5,5, -2,6])
  
  pause
end
hold off
clear s t
disp(' ')
disp(' Another example: The curve (t -> (t, cos(t^2) ) on the interval  ')
disp(' t between 0 and 3 ')
t = linspace( .25, 2.75, 101);
plot(t, cos(t.^2))
axis([0,3, -1.2 1.2])
hold on
pause

tau = linspace( 0, 2*pi, 101);
speed = inline('sqrt(1 + 4*t.^2.*sin(t.^2).^2)');
ss = [.8, 1, 1.2, 1.5, 1.7, 1.8, 2, 2.3, 2.4, 2.5, 2.6];

for j = 1:11
    s = ss(j);
    plot(s, cos(s.^2), '*')
    num = abs(2*sin(s^2) + 4*s^2*cos(s^2));
    kappa = num/speed(s)^3
    rho = 1/kappa;
    N = sign(-2*sin(s^2) -4*s^2*cos(s^2))*[2*s*sin(s^2),1]/speed(s);
    p = [s, cos(s^2) ] + rho*N;
    h = plot(p(1) +rho*cos(tau), p(2) +rho*sin(tau), 'r');
    axis([0,3, -1.2 1.2])
    pause
    delete(h)
end
    
hold off
pause
close

