(*******************************  olympica  *)

Needs["Splines`"]

olympica[1]={{0.813,26.8257},{4.065,26.8257},{7.316,26.8257},{10.568,25.1999},{13.819,24.3870},{17.071,23.5741},{20.323,23.5741},{23.574,24.3870},{26.826,26.0128},{30.077,29.2644},{33.329,31.7031},{36.581,34.1418},{39.832,35.7676},{43.084,37.3934},{46.335,39.0192},{49.587,39.8321},{52.839,41.4579},{56.090,41.4579},{59.342,41.4579},{62.593,41.4579},{65.845,41.4579},{69.097,39.8321},{72.348,39.8321},{75.600,39.8321},{78.851,39.8321},{82.103,39.8321},{85.355,39.8321},{88.606,39.0192},{91.858,38.2063},{95.109,36.5805},{98.361,34.9547},{101.613,34.1418},{104.864,33.3289},{108.116,34.9547},{111.367,36.5805},{114.619,38.2063},{117.871,39.8321},{121.122,42.2708},{124.374,43.0837},{127.625,43.0837},{130.877,44.7095},{134.129,44.7095},{137.380,44.7095},{140.632,44.7095},{143.883,46.3353},{147.135,47.1482},{150.387,47.9611},{153.638,47.9611},{156.890,46.3353},{160.141,46.3353},{163.393,46.3353},{166.645,46.3353},{169.896,44.7095},{173.148,43.8966},{176.399,43.0837},{179.651,41.4579},{182.903,39.0192},{186.154,37.3934},{189.406,35.7676},{192.657,34.1418},{195.909,31.7031},{199.161,29.2644},{202.412,27.6386},{205.664,26.0128},{208.915,25.1999},{212.167,25.1999},{215.419,25.1999},{218.670,26.0128},{221.922,26.8257},{225.173,27.6386},{228.425,28.4515}}
olympica[2]={{0.813,13.8193},{4.065,13.0064},{7.316,12.1935},{10.568,10.5677},{13.819,10.5677},{17.071,12.1935},{20.323,12.1935},{23.574,12.1935},{26.826,12.1935},{30.077,13.8193},{33.329,16.2580},{36.581,20.3225},{39.832,24.3870},{43.084,26.0128},{46.335,28.4515},{49.587,30.8902},{52.839,32.5160},{56.090,34.1418},{59.342,35.7676},{62.593,36.5805},{65.845,36.5805},{69.097,36.5805},{72.348,36.5805},{75.600,36.5805},{78.851,36.5805},{82.103,36.5805},{85.355,36.5805},{88.606,36.5805},{91.858,35.7676},{95.109,34.9547},{98.361,33.3289},{101.613,32.5160},{104.864,30.8902},{108.116,29.2644},{111.367,27.6386},{114.619,26.0128},{117.871,24.3870},{121.122,23.5741},{124.374,24.3870},{127.625,25.1999},{130.877,26.0128},{134.129,28.4515},{137.380,29.2644},{140.632,30.0773},{143.883,30.0773},{147.135,30.0773},{150.387,30.0773},{153.638,29.2644},{156.890,28.4515},{160.141,28.4515},{163.393,28.4515},{166.645,28.4515},{169.896,28.4515},{173.148,29.2644},{176.399,30.0773},{179.651,30.8902},{182.903,31.7031},{186.154,31.7031},{189.406,31.7031},{192.657,30.8902},{195.909,29.2644},{199.161,28.4515},{202.412,27.6386},{205.664,25.1999},{208.915,22.7612},{212.167,19.5096},{215.419,16.2580},{218.670,13.8193},{221.922,12.1935},{225.173,12.1935},{228.425,12.1935},{231.677,12.1935},{234.928,13.0064}}
olympica[3]={{0.813,15.4451},{4.065,15.4451},{7.316,15.4451},{10.568,17.0709},{13.819,21.1354},{17.071,23.5741},{20.323,26.0128},{23.574,27.6386},{26.826,30.0773},{30.077,31.7031},{33.329,31.7031},{36.581,32.5160},{39.832,33.3289},{43.084,34.1418},{46.335,34.9547},{49.587,33.3289},{52.839,33.3289},{56.090,33.3289},{59.342,31.7031},{62.593,30.0773},{65.845,27.6386},{69.097,25.1999},{72.348,22.7612},{75.600,20.3225},{78.851,21.1354},{82.103,25.1999},{85.355,30.0773},{88.606,32.5160},{91.858,35.7676},{95.109,36.5805},{98.361,36.5805},{101.613,38.2063},{104.864,38.2063},{108.116,38.2063},{111.367,36.5805},{114.619,36.5805},{117.871,36.5805},{121.122,36.5805},{124.374,34.9547},{127.625,34.1418},{130.877,32.5160},{134.129,30.8902},{137.380,27.6386},{140.632,25.1999},{143.883,26.0128}}
olympica[4]={{0.813,17.0709},{4.065,17.0709},{7.316,17.8838},{10.568,20.3225},{13.819,22.7612},{17.071,23.5741},{20.323,25.1999},{23.574,26.0128},{26.826,26.8257},{30.077,26.8257},{33.329,26.8257},{36.581,26.8257},{39.832,26.8257},{43.084,25.1999},{46.335,24.3870},{49.587,22.7612},{52.839,20.3225},{56.090,18.6967},{59.342,17.0709},{62.593,17.8838},{65.845,21.1354},{69.097,22.7612},{72.348,24.3870},{75.600,26.0128},{78.851,26.8257},{82.103,28.4515},{85.355,28.4515},{88.606,28.4515},{91.858,28.4515},{95.109,27.6386},{98.361,26.8257},{101.613,26.0128},{104.864,24.3870},{108.116,22.7612},{111.367,21.1354},{114.619,20.3225},{117.871,21.9483}}

(*Poner aqui la familia*)
var=olympica;
(* el número de curvas estudiadas/semillas de la familia*)
m=4;
For[j=1,j≤m,j++,
puntos=var[j];
(* pru es el spline cubico
d es el vector que contiene la información de pru 
n es el número de trozos del spline, es decir, el número de puntos menos 1
*)
pru=SplineFit[puntos,Cubic];
d=InputForm[pru];
n=IntegerPart[d[[1,2,2]]];
spli=ParametricPlot[pru[t],{t,0,n},PlotRange->All, DisplayFunction->Identity];
(* Con los coeficientes se calculan los polinomios cúbicos que dan el spline. Habrá n polinomios para la primera coordenada (X) y otros tantos para la segunda
*)
For[i=0,i<n,i++,
SX[i,t_]=d[[1,4,i+1,1,1]]+d[[1,4,i+1,1,2]]*(t-i)+d[[1,4,i+1,1,3]]*(t-i)^2+d[[1,4,i+1,1,4]]*(t-i)^3];
For[i=0,i<n,i++,SY[i,t_]=d[[1,4,i+1,2,1]]+d[[1,4,i+1,2,2]]*(t-i)+d[[1,4,i+1,2,3]]*(t-i)^2+d[[1,4,i+1,2,4]]*(t-i)^3];
(* Derivada primera y segunda de cada trozo del spline
*)
For[i=0,i<n,i++,DX[i,t_]=d[[1,4,i+1,1,2]]+2*d[[1,4,i+1,1,3]]*(t-i)+3*d[[1,4,i+1,1,4]]*(t-i)^2];
For[i=0,i<n,i++,DY[i,t_]=d[[1,4,i+1,2,2]]+2*d[[1,4,i+1,2,3]]*(t-i)+3*d[[1,4,i+1,2,4]]*(t-i)^2];
For[i=0,i<n,i++,DDX[i,t_]=2*d[[1,4,i+1,1,3]]+6*d[[1,4,i+1,1,4]]*(t-i)];
For[i=0,i<n,i++,DDY[i,t_]=2*d[[1,4,i+1,2,3]]+6*d[[1,4,i+1,2,4]]*(t-i)];
(*Cálculo de la curvatura a trozos
*)
For[i=0,i<n,i++,cur[i,t_]=(DX[i,t]DDY[i,t]-DDX[i,t]DY[i,t])/((DX[i,t])^2+(DY[i,t])^2)^(3/2)];
(* Dibujos de los trozos de curvatura 
*)
For[i=0,i<n,i++,dib[i]=Plot[cur[i,t],{t,i,i+1},DisplayFunction->Identity]];
pp=dib[0];
For[i=1,i<n,i++,pp=Show[pp,dib[i],PlotRange->All]];
(* bez es el spline de Bezier
b es el vector que contiene la información de bez
nb es el número de trozos del spline, es decir, el número de puntos menos 1 (Como nb=n, no se define nuevo)
*)
bez=SplineFit[puntos,Bezier];
b=InputForm[bez];
(*Calculo de las funciones de Bezier para la coordenada X y la Y; la curva es la imagen del intervalo[0,1]*)
For[i=1,i≤n+1,i++,BX[t_]=bez[[4,1,1]]/.#1->t];
For[i=1,i≤n+1,i++,BY[t_]=bez[[4,1,2]]/.#1->t];
dibez[j]=ParametricPlot[{BX[t],BY[t]},{t,0,1},PlotRange->All,DisplayFunction->Identity];
curbe[j,t_]=1000*(BX'[t]BY''[t]-BX''[t]BY'[t])/((BX'[t])^2+(BY'[t])^2)^(3/2);
aa=0.1;
bb=0.9;
cur[j]=Abs[NMinValue[{curbe[j,t],aa<t<bb},t]];
vmed[j]=Abs[NIntegrate[curbe[j,t],{t,aa,bb}]];
vals[j]=Reap[soln=y[x]/. First[NDSolve[{y'[x]==Evaluate[D[curbe[j,x],x]],y[0]==(curbe[j,x]/. x->0)},y[x],{x,aa,bb},Method->{"EventLocator","Event"->y'[x],"EventAction":>Sow[{x,y[x]}]}]]][[2,1]];
Print[ var,"-",j,":"];Print["Máximos y mínimos locales "];
Print[vals[j]];
z=vals[j];
max[j]=Max[Table[z[[k,2]],{k,1,Length[z]}]];
min[j]=Min[Table[z[[k,2]],{k,1,Length[z]}]];dibcurbe[j]=Plot[curbe[j,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[z]}];
Print[dibez[j]];
Print[dibcurbe[j]];
Print[Plot[{curbe[j,t],vmed[j]},{t,0,1},Axes->True,DisplayFunction->Identity,PlotStyle->{RGBColor[0,1,0],{Dotted,Dashed}}]];
Print[ "Máximo valor de la curvatura",max[j]];
Print[ "Mínimo valor de la curvatura",min[j]];Print[ "Máximo valor de la curvatura (en valor absoluto)con otro cálculo",cur[j]];
Print["______________________________________________________"];];
Print["Curvaturas de cada ", var ,":  ", Table[cur[r],{r,1,4}]];
Print["Valores medios de curvatura de cada ", var ," en [0,1]:  ", Table[vmed[j],{j,1,4}]];

Show[Table[dibcurbe[j],{j,1,6}]]

Table[NMinValue[{curbe[j,t],0.25<t<0.75},t],{j,1,6}]

dibcurbe[j],{j,1,6}

Table[dibcurbe[j],{j,1,6}]

curbe[j,t_]
dibcurbe[j]

Plot[curbe[1,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[vals[1]]}]

dibcurbe[j]=Plot[curbe[j,x],{x,0,1},Epilog->{PointSize[Medium],Red,Point[z]}]

dibcurbe2[1]

Print[dibez[1]];

f=vals[1]

Max[vals[1]]

Max[Table[f[[k,2]],{k,1,Length[f]}]]
Min[Table[f[[k,2]],{k,1,Length[f]}]]

List