(*******************************  italica  *)

Needs["Splines`"]

italica[1]={{0.366,28.9377},{1.832,28.5714},{3.297,27.4725},{4.762,27.8388},{6.227,27.1062},{7.692,26.7399},{9.158,26.3736},{10.623,26.0073},{12.088,26.0073},{13.553,26.0073},{15.018,26.0073},{16.484,24.9084},{17.949,24.5421},{19.414,24.1758},{20.879,24.1758},{22.344,28.5714},{22.344,31.1355},{23.810,32.9670},{25.275,36.2637},{26.740,38.8278},{28.205,40.6593},{29.670,42.4908},{31.136,44.3223},{32.601,46.8864},{34.066,47.6190},{35.531,48.7179},{36.996,52.7473},{38.462,53.1136},{39.927,54.2125},{41.392,55.6777},{42.857,57.1429},{44.322,59.3407},{45.788,60.8059},{47.253,61.9048},{48.718,63.7363},{50.183,65.2015},{51.648,67.7656},{53.114,73.6264},{54.579,75.0916},{56.044,76.9231},{57.509,79.1209},{58.974,80.5861},{60.440,82.0513},{61.905,82.4176},{63.370,83.1502},{64.835,83.1502},{66.300,83.1502},{67.766,83.1502},{69.231,83.1502},{70.696,83.5165},{72.161,83.1502},{73.626,82.0513},{75.092,73.2601},{75.092,80.9524},{76.557,68.8645},{78.022,67.3993},{79.487,65.9341},{80.952,64.8352},{82.418,64.1026},{83.883,64.1026},{85.348,63.0037},{86.813,62.2711},{88.278,61.9048},{89.744,61.5385},{91.209,60.4396},{92.674,60.4396},{94.139,59.7070},{95.604,58.6081},{97.070,57.5092},{98.535,57.5092},{100.000,56.4103},{101.465,55.6777},{102.930,54.9451},{104.396,54.2125},{105.861,53.8462},{107.326,52.7473},{108.791,51.2821},{110.256,49.8168},{111.722,48.3517},{113.187,46.8864},{114.652,45.0549},{116.117,42.8571},{117.582,41.7582},{119.048,41.3919},{120.513,41.0256},{121.978,40.2930},{123.443,41.0256},{124.908,42.1245},{126.374,43.9560},{127.839,46.8864},{129.304,48.7179},{130.769,50.5494},{132.234,52.0147},{133.700,53.4799},{135.165,55.3114},{136.630,57.1429},{138.095,58.2418},{139.560,57.8755},{141.026,59.7070},{142.491,61.1722},{143.956,63.0037},{145.421,62.6374},{146.886,63.7363},{148.352,65.2015},{149.817,65.2015},{151.282,66.3004},{152.747,67.0330},{154.212,67.0330},{155.678,67.0330},{157.143,68.1319},{158.608,69.2308},{160.073,69.2308},{161.538,70.3297},{163.004,72.5275},{164.469,73.6264},{165.934,73.6264},{167.399,74.7253},{168.864,75.0916},{170.330,75.0916},{171.795,75.0916},{173.260,75.4579},{174.725,75.0916},{176.190,75.0916},{177.656,75.0916},{179.121,75.0916},{180.586,73.9927},{182.051,72.5275},{183.516,70.6960},{184.982,68.1319},{186.447,68.1319},{187.912,67.3993},{189.377,65.9341},{190.842,65.2015},{192.308,64.8352},{193.773,64.4689},{195.238,63.0037},{196.703,62.2711},{198.169,60.8059},{199.634,59.7070},{201.099,59.7070},{202.564,58.6081},{204.029,57.8755},{205.495,54.9451},{206.960,53.1136},{208.425,52.0147},{209.890,48.3517},{211.355,47.2527},{212.821,45.4212},{214.286,44.6886},{215.751,43.2234},{217.216,41.7582},{218.681,41.0256},{220.147,41.3919},{221.612,41.3919},{223.077,41.3919},{224.542,42.4908},{226.007,42.8571},{227.473,42.8571},{228.938,42.8571},{230.403,44.3223},{231.868,44.3223}}
italica[2]={{0.366,5.4945},{1.832,4.3956},{3.297,4.0293},{4.762,4.0293},{6.227,4.0293},{7.692,4.0293},{9.158,4.0293},{10.623,4.0293},{12.088,4.3956},{13.553,5.4945},{15.018,5.4945},{16.484,5.8608},{17.949,6.9597},{19.414,7.6923},{20.879,8.0586},{22.344,8.7912},{23.810,9.1575},{25.275,9.1575},{26.740,9.8901},{28.205,11.3553},{29.670,11.7216},{31.136,12.0879},{32.601,12.8205},{34.066,15.0183},{35.531,15.0183},{36.996,16.4835},{38.462,17.2161},{39.927,17.9487},{41.392,19.0476},{42.857,19.7802},{44.322,20.5128},{45.788,21.6117},{47.253,21.6117},{48.718,22.7106},{50.183,23.8095},{51.648,23.0769},{53.114,23.8095},{54.579,24.5421},{56.044,25.2747},{57.509,26.0073},{58.974,26.7399},{60.440,27.4725},{61.905,28.2051},{63.370,29.3040},{64.835,30.0366},{66.300,30.4029},{67.766,31.5018},{69.231,31.8681},{70.696,31.8681},{72.161,31.8681},{73.626,31.8681},{75.092,31.8681},{76.557,31.8681},{78.022,32.2344},{79.487,32.9670},{80.952,33.3333},{82.418,33.3333},{83.883,33.3333},{85.348,33.3333},{86.813,33.3333},{88.278,33.3333},{89.744,32.6007},{91.209,31.8681},{92.674,31.1355},{94.139,30.7692},{95.604,30.0366},{97.070,29.6703},{98.535,29.6703},{100.000,29.6703},{101.465,29.3040},{102.930,28.2051},{104.396,28.2051},{105.861,27.1062},{107.326,26.7399},{108.791,26.0073},{110.256,24.9084},{111.722,23.0769},{113.187,23.0769},{114.652,20.8791},{116.117,19.4139},{117.582,17.9487},{119.048,16.4835},{120.513,16.1172},{121.978,15.0183},{123.443,15.0183},{124.908,15.0183},{126.374,13.9194},{127.839,12.8205},{129.304,13.1868},{130.769,12.8205},{132.234,12.8205},{133.700,12.8205},{135.165,12.8205},{136.630,13.1868},{138.095,14.2857},{139.560,15.0183},{141.026,16.1172},{142.491,16.4835},{143.956,17.5824},{145.421,18.6813},{146.886,20.1465},{148.352,21.6117},{149.817,22.7106},{151.282,24.1758},{152.747,25.6410},{154.212,26.3736},{155.678,27.1062},{157.143,27.4725},{158.608,28.2051},{160.073,28.9377},{161.538,28.9377},{163.004,29.6703},{164.469,29.6703},{165.934,29.6703},{167.399,29.6703},{168.864,30.0366},{170.330,30.7692},{171.795,31.1355},{173.260,31.1355},{174.725,31.5018},{176.190,32.6007},{177.656,32.6007},{179.121,32.6007},{180.586,33.6996},{182.051,34.0659},{183.516,34.0659},{184.982,34.0659},{186.447,34.7985},{187.912,34.7985},{189.377,34.0659},{190.842,34.7985},{192.308,34.4322},{193.773,34.0659},{195.238,34.0659},{196.703,34.0659},{198.169,34.0659},{199.634,34.0659},{201.099,34.0659},{202.564,32.6007},{204.029,31.8681},{205.495,30.4029},{206.960,29.6703},{208.425,28.9377},{209.890,28.9377},{211.355,27.8388},{212.821,26.3736},{214.286,26.0073},{215.751,26.0073},{217.216,24.9084},{218.681,24.1758},{220.147,23.0769},{221.612,22.3443},{223.077,20.5128},{224.542,19.0476},{226.007,16.8498},{227.473,15.3846},{228.938,14.6520},{230.403,14.2857},{231.868,14.2857},{233.333,15.3846},{234.799,15.7509},{236.264,15.7509}}
italica[3]={{0.366,29.6703},{1.832,28.9377},{3.297,27.8388},{4.762,26.3736},{6.227,26.0073},{7.692,24.1758},{9.158,24.1758},{10.623,26.0073},{12.088,28.9377},{13.553,31.1355},{15.018,33.6996},{16.484,35.1648},{17.949,36.6300},{19.414,37.3626},{20.879,38.8278},{22.344,40.2930},{23.810,42.1245},{25.275,42.4908},{26.740,43.9560},{28.205,44.3223},{29.670,46.1538},{31.136,46.8864},{32.601,47.6190},{34.066,47.9853},{35.531,49.0842},{36.996,49.8168},{38.462,51.6483},{39.927,54.9451},{41.392,57.5092},{42.857,59.3407},{44.322,60.4396},{45.788,61.5385},{47.253,63.7363},{48.718,64.1026},{50.183,64.8352},{51.648,64.8352},{53.114,63.7363},{54.579,62.6374},{56.044,61.9048},{57.509,61.1722},{58.974,59.3407},{60.440,57.5092},{61.905,53.1136},{63.370,51.2821},{64.835,50.1832},{66.300,49.4506},{67.766,48.7179},{69.231,47.9853},{70.696,47.9853},{72.161,46.8864},{73.626,45.7875},{75.092,45.7875},{76.557,45.4212},{78.022,43.9560},{79.487,42.8571},{80.952,41.3919},{82.418,41.3919},{83.883,40.6593},{85.348,39.5604},{86.813,38.0952},{88.278,37.3626},{89.744,35.5311},{91.209,34.0659},{92.674,33.6996},{94.139,32.2344},{95.604,29.6703},{97.070,27.1062},{98.535,25.6410},{100.000,24.9084},{101.465,24.5421},{102.930,24.9084},{104.396,26.0073},{105.861,27.1062},{107.326,28.5714},{108.791,29.3040},{110.256,31.1355},{111.722,32.2344},{113.187,34.0659},{114.652,36.6300},{116.117,38.0952},{117.582,38.8278},{119.048,40.2930},{120.513,41.0256},{121.978,42.4908},{123.443,43.5897},{124.908,44.6886},{126.374,45.4212},{127.839,46.5201},{129.304,47.2527},{130.769,47.9853},{132.234,48.3517},{133.700,49.8168},{135.165,50.1832},{136.630,50.5494},{138.095,51.6483},{139.560,53.8462},{141.026,56.4103},{142.491,56.7766},{143.956,58.2418},{145.421,59.3407},{146.886,59.7070},{148.352,59.7070},{149.817,59.7070},{151.282,59.7070},{152.747,58.9744},{154.212,58.6081},{155.678,57.5092},{157.143,56.7766},{158.608,55.6777},{160.073,53.1136},{161.538,50.1832},{163.004,47.9853},{164.469,47.6190},{165.934,46.1538},{167.399,45.7875},{168.864,45.7875},{170.330,45.0549},{171.795,43.9560},{173.260,42.8571},{174.725,42.1245},{176.190,41.0256},{177.656,39.5604},{179.121,39.1941},{180.586,38.4615},{182.051,37.3626},{183.516,35.8974},{184.982,35.1648},{186.447,34.0659},{187.912,32.2344},{189.377,30.4029},{190.842,28.5714},{192.308,25.6410},{193.773,24.1758},{195.238,22.3443},{196.703,20.5128},{198.169,19.0476},{199.634,18.6813},{201.099,17.5824},{202.564,16.8498},{204.029,16.4835},{205.495,17.2161},{206.960,17.9487},{208.425,17.9487},{209.890,17.2161},{211.355,17.9487},{212.821,18.3150},{214.286,18.6813},{215.751,18.6813},{217.216,19.4139}}
italica[4]={{0.366,64.1026},{1.832,62.6374},{3.297,60.4396},{4.762,59.3407},{6.227,59.7070},{7.692,60.4396},{9.158,60.4396},{10.623,61.1722},{12.088,61.1722},{13.553,62.2711},{15.018,63.0037},{16.484,63.3700},{17.949,63.3700},{19.414,63.7363},{20.879,64.1026},{22.344,64.1026},{23.810,64.4689},{25.275,64.8352},{26.740,65.2015},{28.205,65.2015},{29.670,66.3004},{31.136,66.6667},{32.601,66.3004},{34.066,67.0330},{35.531,67.0330},{36.996,67.0330},{38.462,68.4982},{39.927,68.4982},{41.392,68.4982},{42.857,68.1319},{44.322,68.4982},{45.788,67.7656},{47.253,66.6667},{48.718,66.6667},{50.183,66.3004},{51.648,65.5678},{53.114,64.8352},{54.579,64.4689},{56.044,63.3700},{57.509,63.3700},{58.974,63.3700},{60.440,61.9048},{61.905,61.9048},{63.370,61.9048},{64.835,60.8059},{66.300,60.4396},{67.766,60.0733},{69.231,59.7070},{70.696,58.2418},{72.161,58.2418},{73.626,56.7766},{75.092,56.7766},{76.557,55.6777},{78.022,55.3114},{79.487,54.2125},{80.952,53.1136},{82.418,52.3810},{83.883,52.0147},{85.348,50.5494},{86.813,48.3517},{88.278,46.8864},{89.744,45.7875},{91.209,44.3223},{92.674,43.5897},{94.139,43.2234},{95.604,42.1245},{97.070,42.1245},{98.535,42.1245},{100.000,44.3223},{101.465,46.5201},{102.930,47.2527},{104.396,49.0842},{105.861,50.9158},{107.326,50.9158},{108.791,51.6483},{110.256,52.7473},{111.722,53.1136},{113.187,53.8462},{114.652,54.5788},{116.117,55.3114},{117.582,55.3114},{119.048,55.3114},{120.513,56.0440},{121.978,56.0440},{123.443,56.0440},{124.908,57.1429},{126.374,58.2418},{127.839,57.8755},{129.304,57.5092},{130.769,57.8755},{132.234,58.2418},{133.700,58.2418},{135.165,58.2418},{136.630,58.9744},{138.095,58.9744},{139.560,58.9744},{141.026,59.7070},{142.491,60.0733},{143.956,61.5385},{145.421,65.9341},{146.886,66.3004},{148.352,67.7656},{149.817,68.8645},{151.282,69.2308},{152.747,71.0623},{154.212,71.4286},{155.678,71.4286},{157.143,71.4286},{158.608,71.0623},{160.073,70.6960},{161.538,69.9634},{163.004,69.2308},{164.469,68.8645},{165.934,65.5678},{165.934,67.7656},{167.399,55.3114},{167.399,58.6081},{167.399,65.2015},{168.864,53.4799},{170.330,52.0147},{171.795,49.8168},{173.260,47.6190},{174.725,46.1538},{176.190,43.9560},{177.656,42.4908},{179.121,40.6593},{179.121,42.4908},{180.586,40.2930},{182.051,38.4615},{183.516,35.1648},{183.516,38.0952},{184.982,32.9670},{186.447,31.8681},{187.912,25.6410},{187.912,28.5714},{189.377,21.6117},{190.842,21.2454},{192.308,22.3443},{193.773,23.4432}}

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