(*******************************  oreophilla  *)

Needs["Splines`"]

oreophilla[1]={{0.4184,6.6936},{2.0918,5.8569},{3.7652,4.1835},{5.4386,2.5101},{7.1120,3.3468},{8.7854,9.6221},{10.4588,12.9689},{12.1322,15.0607},{13.8056,16.7341},{15.4790,17.9891},{17.1524,18.4075},{18.8258,18.8258},{20.4992,19.6625},{22.1726,19.6625},{23.8460,19.6625},{25.5194,19.6625},{27.1928,18.8258},{28.8663,18.4075},{30.5397,17.5708},{32.2131,15.8974},{33.8865,13.8056},{35.5599,11.7138},{37.2333,9.6221},{38.9067,6.6936},{40.5801,7.5303},{42.2535,8.3670},{43.9269,10.4588},{45.6003,13.8056},{47.2737,16.3157},{48.9471,18.4075},{50.6205,20.0809},{52.2939,21.3359},{53.9673,22.5910},{55.6407,23.0093},{57.3141,23.0093},{58.9876,23.0093},{60.6610,23.0093},{62.3344,23.0093},{64.0078,22.5910},{65.6812,21.7543},{67.3546,20.9176},{69.0280,19.2442},{70.7014,16.7341},{72.3748,12.5505},{74.0482,13.3872}}
oreophilla[2]={{0.418,14.6423},{2.092,14.2239},{3.765,12.9689},{5.439,12.5505},{7.112,13.3872},{8.785,16.3157},{10.459,19.6625},{12.132,23.0093},{13.806,25.1011},{15.479,27.6112},{17.152,28.4479},{18.826,29.7030},{20.499,30.5397},{22.173,31.3764},{23.846,31.3764},{25.519,32.2131},{27.193,32.2131},{28.866,32.2131},{30.540,31.3764},{32.213,31.3764},{33.886,30.5397},{35.560,29.7030},{37.233,29.2846},{38.907,28.4479},{40.580,27.6112},{42.253,26.7745},{43.927,25.5194},{45.600,23.4277},{47.274,21.7543},{48.947,20.9176},{50.621,19.6625},{52.294,19.6625},{53.967,18.8258},{55.641,19.2442},{57.314,21.7543},{58.988,25.1011},{60.661,26.7745},{62.334,28.8663},{64.008,30.1213},{65.681,31.7947},{67.355,33.0498},{69.028,33.8865},{70.701,34.3048},{72.375,34.7232},{74.048,35.1415},{75.722,35.5599},{77.395,35.1415},{79.068,34.7232},{80.742,33.8865},{82.415,33.0498},{84.089,31.7947},{85.762,30.9580},{87.435,29.2846},{89.109,28.0295},{90.782,25.9378},{92.456,23.4277},{94.129,20.4992},{95.802,18.8258},{97.476,17.9891},{99.149,17.9891},{100.823,17.9891},{102.496,18.4075},{104.170,19.2442},{105.843,20.4992},{107.516,22.5910},{109.190,24.2644}}
oreophilla[3]={{0.4184,10.0404},{2.0918,9.2037},{3.7652,7.5303},{5.4386,7.1120},{7.1120,7.1120},{8.7854,7.5303},{10.4588,8.7854},{12.1322,9.2037},{13.8056,12.1322},{15.4790,16.3157},{17.1524,19.2442},{18.8258,20.9176},{20.4992,22.5910},{22.1726,23.8460},{23.8460,25.1011},{25.5194,26.3561},{27.1928,26.3561},{28.8663,26.3561},{30.5397,26.3561},{32.2131,26.3561},{33.8865,26.3561},{35.5599,25.9378},{37.2333,25.5194},{38.9067,24.6827},{40.5801,23.8460},{42.2535,22.5910},{43.9269,22.1726},{45.6003,20.0809},{47.2737,18.8258},{48.9471,17.1524},{50.6205,15.0607},{52.2939,15.0607},{53.9673,16.7341},{55.6407,18.4075},{57.3141,20.0809},{58.9876,20.9176},{60.6610,22.1726},{62.3344,23.0093},{64.0078,23.8460},{65.6812,24.2644},{67.3546,24.6827},{69.0280,24.6827},{70.7014,24.6827},{72.3748,24.6827},{74.0482,24.6827},{75.7216,23.8460},{77.3950,23.0093},{79.0684,22.5910},{80.7418,22.1726},{82.4152,20.4992},{84.0886,19.6625},{85.7620,18.4075},{87.4355,16.7341},{89.1089,15.0607},{90.7823,12.9689},{92.4557,10.0404},{94.1291,9.6221},{95.8025,10.8771}}
oreophilla[4]={{0.4184,6.6936},{2.0918,5.8569},{3.7652,5.4386},{5.4386,5.4386},{7.1120,6.6936},{8.7854,10.0404},{10.4588,13.3872},{12.1322,15.8974},{13.8056,17.1524},{15.4790,19.2442},{17.1524,20.0809},{18.8258,21.3359},{20.4992,22.1726},{22.1726,22.5910},{23.8460,23.0093},{25.5194,23.0093},{27.1928,23.8460},{28.8663,23.8460},{30.5397,23.4277},{32.2131,23.0093},{33.8865,22.1726},{35.5599,21.3359},{37.2333,20.0809},{38.9067,18.8258},{40.5801,17.5708},{42.2535,15.0607},{43.9269,12.5505},{45.6003,11.2955},{47.2737,8.7854},{48.9471,9.2037},{50.6205,11.2955},{52.2939,14.6423},{53.9673,16.7341},{55.6407,17.9891},{57.3141,19.2442},{58.9876,20.0809},{60.6610,20.4992},{62.3344,21.3359},{64.0078,21.7543},{65.6812,20.4992},{67.3546,20.4992},{69.0280,20.4992},{70.7014,20.4992},{72.3748,20.4992},{74.0482,20.4992},{75.7216,20.4992},{77.3950,19.2442},{79.0684,18.4075},{80.7418,17.5708},{82.4152,15.4790},{84.0886,13.3872},{85.7620,10.0404},{87.4355,6.6936},{89.1089,4.6019},{90.7823,5.0202},{92.4557,6.6936}}

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