(*******************************  chlorifolia  *)

Needs["Splines`"]

chlorifolia[1]={{0.547,11.4879},{2.735,10.3938},{4.923,9.2997},{7.112,10.9409},{9.300,12.0349},{11.488,13.1290},{13.676,13.6761},{15.864,15.3172},{18.052,17.5054},{20.241,19.6935},{22.429,20.7876},{24.617,21.3347},{26.805,21.8817},{28.993,24.0699},{31.181,25.7110},{33.370,27.3521},{35.558,28.9933},{37.746,28.9933},{39.934,29.5403},{42.122,31.1815},{44.310,31.7285},{46.499,32.2755},{48.687,32.2755},{50.875,32.2755},{53.063,32.2755},{55.251,31.7285},{57.440,31.1815},{59.628,31.1815},{61.816,31.1815},{64.004,30.0874},{66.192,30.0874},{68.380,29.5403},{70.569,27.8992},{72.757,27.8992},{74.945,26.8051},{77.133,26.2581},{79.321,24.0699},{81.509,22.4288},{83.698,20.7876},{85.886,19.6935},{88.074,18.0524},{90.262,18.0524},{92.450,15.8642},{94.638,15.8642},{96.827,16.4113},{99.015,18.5995},{101.203,21.8817},{103.391,25.1640},{105.579,26.8051},{107.767,30.6344},{109.956,35.0108},{112.144,36.6519},{114.332,37.1989},{116.520,37.1989},{118.708,38.2930},{120.897,40.4812},{123.085,41.0282},{125.273,41.5753},{127.461,42.6694},{129.649,43.7634},{131.837,44.3105},{134.026,43.7634},{136.214,43.2164},{138.402,44.3105},{140.590,44.3105},{142.778,44.3105},{144.966,44.3105},{147.155,44.3105},{149.343,44.3105},{151.531,43.2164},{153.719,43.2164},{155.907,43.2164},{158.095,43.2164},{160.284,42.6694},{162.472,41.5753},{164.660,39.9341},{166.848,39.9341},{169.036,39.9341},{171.224,38.2930},{173.413,36.6519},{175.601,35.0108},{177.789,34.4637},{179.977,32.8226},{182.165,31.7285},{184.353,29.5403},{186.542,27.3521},{188.730,24.6169},{190.918,24.6169},{193.106,21.8817},{195.294,18.5995},{197.483,17.5054},{199.671,16.9583},{201.859,16.9583},{204.047,18.0524},{206.235,19.1465},{208.423,19.6935}}
chlorifolia[2]={{0.547,31.7285},{2.735,29.5403},{4.923,28.9933},{7.112,28.4462},{9.300,29.5403},{11.488,30.6344},{13.676,31.1815},{15.864,32.8226},{18.052,35.0108},{20.241,37.7460},{22.429,41.5753},{24.617,43.7634},{26.805,45.9516},{28.993,47.5927},{31.181,48.6868},{33.370,48.6868},{35.558,50.3280},{37.746,51.4220},{39.934,51.9691},{42.122,51.9691},{44.310,53.0632},{46.499,53.0632},{48.687,53.0632},{50.875,53.0632},{53.063,53.0632},{55.251,53.0632},{57.440,53.0632},{59.628,53.0632},{61.816,53.0632},{64.004,52.5161},{66.192,51.4220},{68.380,50.8750},{70.569,49.7809},{72.757,48.6868},{74.945,49.7809},{77.133,48.1398},{79.321,44.3105},{81.509,44.3105},{83.698,43.2164},{85.886,40.4812},{88.074,38.2930},{90.262,37.7460},{92.450,36.6519},{94.638,36.1048},{96.827,33.9167},{99.015,30.6344},{101.203,28.9933},{103.391,28.9933},{105.579,28.9933},{107.767,29.5403},{109.956,31.1815},{112.144,31.7285},{114.332,32.2755},{116.520,33.3696},{118.708,35.0108},{120.897,38.2930},{123.085,40.4812},{125.273,41.0282},{127.461,42.1223},{129.649,42.1223},{131.837,42.6694},{134.026,42.6694},{136.214,44.3105},{138.402,45.4046},{140.590,46.4987},{142.778,46.4987},{144.966,46.4987},{147.155,46.4987},{149.343,47.5927},{151.531,47.5927},{153.719,47.5927},{155.907,46.4987},{158.095,46.4987},{160.284,45.9516},{162.472,44.3105},{164.660,44.3105},{166.848,43.2164},{169.036,43.2164},{171.224,42.1223},{173.413,42.1223},{175.601,41.5753},{177.789,39.9341},{179.977,39.9341},{182.165,37.7460},{184.353,36.6519},{186.542,34.4637},{188.730,32.2755},{190.918,30.6344},{193.106,29.5403},{195.294,27.3521},{197.483,24.0699},{199.671,22.9758},{201.859,20.2406},{204.047,19.1465},{206.235,19.1465},{208.423,20.2406},{210.612,21.3347}}
chlorifolia[3]={{0.547,20.7876},{2.735,22.4288},{4.923,23.5229},{7.112,24.0699},{9.300,26.8051},{11.488,29.5403},{13.676,31.7285},{15.864,33.9167},{18.052,34.4637},{20.241,35.5578},{22.429,37.1989},{24.617,37.7460},{26.805,38.2930},{28.993,38.8401},{31.181,39.9341},{33.370,41.0282},{35.558,41.0282},{37.746,41.0282},{39.934,41.0282},{42.122,41.0282},{44.310,41.0282},{46.499,41.0282},{48.687,41.5753},{50.875,41.0282},{53.063,40.4812},{55.251,39.9341},{57.440,38.8401},{59.628,38.8401},{61.816,39.3871},{64.004,39.3871},{66.192,38.2930},{68.380,37.7460},{70.569,37.1989},{72.757,36.6519},{74.945,35.5578},{77.133,33.9167},{79.321,32.2755},{81.509,30.6344},{83.698,28.4462},{85.886,26.8051},{88.074,23.5229},{90.262,21.3347},{92.450,19.1465},{94.638,19.1465},{96.827,20.7876},{99.015,22.9758},{101.203,25.7110},{103.391,28.4462},{105.579,29.5403},{107.767,30.0874},{109.956,31.7285},{112.144,33.3696},{114.332,33.9167},{116.520,35.0108},{118.708,36.1048},{120.897,35.5578},{123.085,35.0108},{125.273,35.5578},{127.461,36.1048},{129.649,37.1989},{131.837,37.7460},{134.026,38.8401},{136.214,38.8401},{138.402,38.8401},{140.590,37.7460},{142.778,36.6519},{144.966,36.6519},{147.155,35.0108},{149.343,32.8226},{151.531,31.7285},{153.719,31.1815},{155.907,30.0874},{158.095,28.4462},{160.284,27.8992},{162.472,26.2581},{164.660,24.0699},{166.848,21.8817},{169.036,19.6935},{171.224,17.5054},{173.413,15.3172},{175.601,13.6761},{177.789,11.4879},{179.977,7.6586},{182.165,7.6586},{184.353,8.2056},{186.542,9.2997}}
chlorifolia[4]={{0.547,12.5820},{2.735,12.5820},{4.923,11.4879},{7.112,11.4879},{9.300,9.8468},{11.488,8.7527},{13.676,8.2056},{15.864,10.3938},{18.052,13.1290},{20.241,15.3172},{22.429,18.0524},{24.617,20.7876},{26.805,22.9758},{28.993,25.7110},{31.181,27.8992},{33.370,29.5403},{35.558,31.7285},{37.746,33.9167},{39.934,35.5578},{42.122,36.6519},{44.310,37.7460},{46.499,38.8401},{48.687,39.3871},{50.875,39.9341},{53.063,39.9341},{55.251,40.4812},{57.440,41.5753},{59.628,42.1223},{61.816,42.1223},{64.004,42.1223},{66.192,42.1223},{68.380,41.5753},{70.569,41.0282},{72.757,39.9341},{74.945,40.4812},{77.133,39.3871},{79.321,38.2930},{81.509,37.7460},{83.698,37.7460},{85.886,37.7460},{88.074,37.1989},{90.262,36.1048},{92.450,35.0108},{94.638,34.4637},{96.827,33.3696},{99.015,32.8226},{101.203,32.2755},{103.391,32.2755},{105.579,29.5403},{107.767,26.2581},{109.956,23.5229},{112.144,26.2581},{114.332,26.8051},{116.520,27.8992},{118.708,29.5403},{120.897,31.7285},{123.085,33.3696},{125.273,34.4637},{127.461,35.5578},{129.649,37.7460},{131.837,38.8401},{134.026,39.3871},{136.214,40.4812},{138.402,42.6694},{140.590,43.2164},{142.778,43.2164},{144.966,43.7634},{147.155,44.3105},{149.343,44.3105},{151.531,44.3105},{153.719,44.3105},{155.907,43.7634},{158.095,44.3105},{160.284,44.3105},{162.472,44.3105},{164.660,43.7634},{166.848,43.2164},{169.036,42.6694},{171.224,42.1223},{173.413,41.5753},{175.601,39.3871},{177.789,37.1989},{179.977,36.6519},{182.165,35.5578},{184.353,33.3696},{186.542,30.6344},{188.730,28.4462},{190.918,26.8051},{193.106,23.5229},{195.294,20.2406},{197.483,18.5995},{199.671,19.6935},{201.859,21.8817}}

(*Poner aqui la familia*)
var=chlorifolia;
(* 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