Vettore tangente a una curva

import graph3;
settings.render=1;
import animate;
animation A=animation("movietang");
int NN=20;
real h=1/NN;

pair f1(real t) {
return ( 0.5*(1-t)^3+3*3.5*(1-t)*t*t+3.5*t*t*t ,  -0.5*(1-t)^3+3*3.5*(1-t)^2*t  +3*3.5*(1-t)*t*t+2.5*t*t*t  );
}

pair f1p(real t) {
return ( -3*0.5*(1-t)^2+6*3.5*(1-t)*t-3*3.5*t*t+3*3.5*t*t , +3*0.5*(1-t)^2-6*3.5*(1-t)*t+3*3.5*(1-t)^2 +6*3.5*(1-t)*t-3*3.5*t*t+3*2.5*t*t   );
}

pair f2(real t) {
return ( 3.5*(1-t)^3+3*3.5*(1-t)^2*t+4*t*t*t ,  2.5*(1-t)^3+3*1.5*(1-t)^2*t +0.3*t*t*t  );
}

pair f2p(real t) {
return ( -3*3.5*(1-t)^2-6*3.5*(1-t)*t+ 3*3.5*(1-t)^2+3*4*t*t , -3*2.5*(1-t)^2-6*1.5*(1-t)*t+3*1.5*(1-t)^2+3*0.3*t*t   );
}

for(int i=0; i < NN+1; ++i) {
  picture pic;
  size(pic,20cm, 0);
  draw(pic,(-1,0) -- (5.5,0), arrow=Arrow(), L=Label("$x$", position=EndPoint));
  draw(pic,(0,-1) -- (0,3.5), arrow=Arrow(), L=Label("$y$", position=EndPoint));
  draw(pic,(0.5, -0.5) .. controls(0,3.5) and (3.5,3.5) .. (3.5, 2.5));
  draw(pic,(3.5, 2.5) .. controls(3.5,1.5) and (0,0.) .. (4., 0.3));
  real t=i*h;
  path spiral = graph(f1, t, t, operator ..);
  draw(pic,spiral, red+linewidth(4));
  draw(pic,f1(t) -- f1(t)+0.2*f1p(t), arrow=Arrow(5bp), blue+linewidth(2));
  A.add(pic);
  save();
}

for(int i=0; i < NN+1; ++i) {
  picture pic;
  size(pic,20cm, 0);
  draw(pic,(-1,0) -- (5.5,0), arrow=Arrow(), L=Label("$x$", position=EndPoint));
  draw(pic,(0,-1) -- (0,3.5), arrow=Arrow(), L=Label("$y$", position=EndPoint));
  draw(pic,(0.5, -0.5) .. controls(0,3.5) and (3.5,3.5) .. (3.5, 2.5));
  draw(pic,(3.5, 2.5) .. controls(3.5,1.5) and (0,0.) .. (4., 0.3));
  real t=i*h;
  path spiral = graph(f2, t, t, operator ..);
  draw(pic,spiral, red+linewidth(4));
  draw(pic,f2(t) -- f2(t)+0.2*f2p(t), arrow=Arrow(5bp), blue+linewidth(2));
  A.add(pic);
  save();
}

A.movie(loops=3,delay=300);
Link al pdf animato (visualizzabile con Acrobat Reader)