(*******************************  eremitica  *)

Needs["Splines`"]

eremitica[1]={{0.353,19.7801},{1.766,19.0737},{3.179,18.0140},{4.592,18.7204},{6.005,18.7204},{7.418,18.7204},{8.830,19.0737},{10.243,19.7801},{11.656,21.1929},{13.069,21.8994},{14.482,24.0187},{15.895,24.7251},{17.308,26.4912},{18.720,27.9040},{20.133,28.2573},{21.546,28.6105},{22.959,28.6105},{24.372,28.6105},{25.785,28.6105},{27.198,28.9637},{28.610,29.6701},{30.023,29.6701},{31.436,29.3169},{32.849,29.3169},{34.262,29.3169},{35.675,28.6105},{37.088,29.3169},{38.501,29.3169},{39.913,28.9637},{41.326,29.3169},{42.739,28.9637},{44.152,28.6105},{45.565,28.6105},{46.978,28.9637},{48.391,28.9637},{49.803,27.9040},{51.216,27.9040},{52.629,26.4912},{54.042,25.4315},{55.455,22.9590},{55.455,25.0783},{56.868,21.5462},{58.281,22.2526},{59.693,22.9590},{61.106,22.9590},{62.519,22.9590},{63.932,22.6058},{65.345,22.2526},{66.758,22.6058},{68.171,23.3122},{69.584,24.3719},{70.996,25.0783},{72.409,25.7848},{73.822,26.1380},{75.235,26.8444},{76.648,27.1976},{78.061,28.2573},{79.474,28.6105},{80.886,28.6105},{82.299,28.6105},{83.712,28.9637},{85.125,28.6105},{86.538,28.9637},{87.951,28.9637},{89.364,28.6105},{90.776,28.6105},{92.189,29.3169},{93.602,29.6701},{95.015,30.0233},{96.428,29.3169},{97.841,28.9637},{99.254,28.2573},{100.666,27.9040},{102.079,27.5508},{103.492,27.1976},{104.905,27.1976},{106.318,27.1976},{107.731,26.8444},{109.144,26.4912},{110.557,26.4912},{111.969,25.4315},{113.382,24.7251},{114.795,22.6058},{116.208,22.2526},{117.621,20.1333},{119.034,19.7801},{120.447,18.0140},{121.859,15.8947},{123.272,15.8947},{124.685,15.8947}}
eremitica[2]={{0.353,13.4222},{1.766,14.4818},{3.179,15.5415},{4.592,15.8947},{6.005,15.8947},{7.418,15.8947},{8.830,16.6011},{10.243,17.3076},{11.656,18.3672},{13.069,18.7204},{14.482,18.7204},{15.895,18.7204},{17.308,19.7801},{18.720,20.1333},{20.133,20.8397},{21.546,20.8397},{22.959,21.5462},{24.372,21.8994},{25.785,22.6058},{27.198,23.3122},{28.610,23.6655},{30.023,23.3122},{31.436,24.0187},{32.849,24.0187},{34.262,23.6655},{35.675,24.3719},{37.088,24.0187},{38.501,24.0187},{39.913,24.7251},{41.326,24.3719},{42.739,24.3719},{44.152,24.3719},{45.565,24.3719},{46.978,24.3719},{48.391,24.3719},{49.803,24.3719},{51.216,23.6655},{52.629,24.3719},{54.042,24.3719},{55.455,23.6655},{56.868,24.0187},{58.281,23.3122},{59.693,22.9590},{61.106,22.6058},{62.519,21.8994},{63.932,20.8397},{65.345,20.4865},{66.758,19.7801},{68.171,19.0737},{69.584,18.0140},{70.996,18.7204},{72.409,19.7801},{73.822,20.1333},{75.235,20.1333},{76.648,20.8397},{78.061,20.8397},{79.474,21.8994},{80.886,22.6058},{82.299,23.3122},{83.712,23.6655},{85.125,23.3122},{86.538,24.0187},{87.951,24.3719},{89.364,23.6655},{90.776,24.3719},{92.189,24.0187},{93.602,24.0187},{95.015,24.3719},{96.428,24.3719},{97.841,24.3719},{99.254,24.0187},{100.666,24.0187},{102.079,23.6655},{103.492,23.6655},{104.905,22.9590},{106.318,22.9590},{107.731,22.6058},{109.144,22.9590},{110.557,22.2526},{111.969,22.2526},{113.382,22.6058},{114.795,22.2526},{116.208,21.5462},{117.621,21.1929},{119.034,20.8397},{120.447,20.4865},{121.859,20.1333},{123.272,20.1333},{124.685,20.1333},{126.098,20.8397},{127.511,20.4865},{128.924,20.8397},{130.337,21.5462},{131.749,20.8397},{133.162,21.1929},{134.575,21.5462},{135.988,21.5462}}
eremitica[3]={{0.353,15.89471},{1.766,15.18828},{3.179,15.18828},{4.592,14.83506},{6.005,14.83506},{7.418,14.83506},{8.830,15.54149},{10.243,16.95436},{11.656,17.30757},{13.069,17.30757},{14.482,18.01401},{15.895,18.72044},{17.308,19.42687},{18.720,19.42687},{20.133,19.78008},{21.546,20.13330},{22.959,20.13330},{24.372,20.13330},{25.785,20.83973},{27.198,20.13330},{28.610,20.13330},{30.023,20.48652},{31.436,20.13330},{32.849,20.13330},{34.262,20.13330},{35.675,20.83973},{37.088,20.83973},{38.501,20.48652},{39.913,20.48652},{41.326,20.48652},{42.739,20.13330},{44.152,20.13330},{45.565,20.13330},{46.978,19.42687},{48.391,18.72044},{49.803,19.78008},{51.216,20.13330},{52.629,20.13330},{54.042,19.07365},{55.455,18.01401},{56.868,18.01401},{58.281,18.01401},{59.693,18.01401},{61.106,18.01401},{62.519,17.30757},{63.932,18.01401},{65.345,18.01401},{66.758,18.01401},{68.171,19.07365},{69.584,19.42687},{70.996,19.78008},{72.409,20.13330},{73.822,19.42687},{75.235,18.72044},{76.648,18.01401},{78.061,18.36722},{79.474,18.72044},{80.886,18.72044},{82.299,18.36722},{83.712,17.66079},{85.125,17.30757},{86.538,17.30757},{87.951,16.95436},{89.364,15.54149},{90.776,15.18828},{92.189,14.48185},{93.602,14.12863},{95.015,12.36255},{96.428,12.71577},{97.841,12.00934},{99.254,11.65612},{100.666,11.65612},{102.079,11.65612},{103.492,11.65612},{104.905,10.94969},{106.318,10.94969},{107.731,11.30291},{109.144,11.65612},{110.557,11.30291}}
eremitica[4]={{0.353,11.3029},{1.766,10.9497},{3.179,11.6561},{4.592,11.6561},{6.005,12.0093},{7.418,14.4818},{8.830,15.8947},{10.243,17.3076},{11.656,18.0140},{13.069,18.3672},{14.482,19.0737},{15.895,19.4269},{17.308,19.7801},{18.720,20.8397},{20.133,20.8397},{21.546,20.8397},{22.959,20.8397},{24.372,21.5462},{25.785,22.2526},{27.198,22.9590},{28.610,22.2526},{30.023,22.9590},{31.436,22.2526},{32.849,22.9590},{34.262,22.9590},{35.675,22.9590},{37.088,24.0187},{38.501,24.7251},{39.913,25.0783},{41.326,26.1380},{42.739,26.4912},{44.152,27.1976},{45.565,27.1976},{46.978,26.4912},{48.391,27.5508},{49.803,27.9040},{51.216,28.6105},{52.629,28.6105},{54.042,28.6105},{55.455,28.6105},{56.868,28.6105},{58.281,28.2573},{59.693,27.5508},{61.106,26.8444},{62.519,27.1976},{63.932,26.4912},{65.345,26.8444},{66.758,27.1976},{68.171,28.2573},{69.584,29.3169},{70.996,29.3169},{72.409,29.3169},{73.822,30.7298},{75.235,30.7298},{76.648,30.7298},{78.061,30.7298},{79.474,30.7298},{80.886,30.7298},{82.299,30.7298},{83.712,30.7298},{85.125,30.7298},{86.538,30.7298},{87.951,30.7298},{89.364,30.7298},{90.776,30.7298},{92.189,30.0233},{93.602,30.0233},{95.015,30.0233},{96.428,29.6701},{97.841,29.3169},{99.254,29.3169},{100.666,29.3169},{102.079,28.9637},{103.492,28.6105},{104.905,28.6105},{106.318,28.2573},{107.731,28.6105},{109.144,29.3169},{110.557,29.3169},{111.969,28.6105},{113.382,28.6105},{114.795,27.1976},{116.208,26.8444},{117.621,27.1976},{119.034,24.3719},{120.447,25.0783},{121.859,25.0783},{123.272,24.3719},{124.685,24.0187},{126.098,22.9590},{127.511,21.5462},{128.924,21.5462},{130.337,21.1929}}

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