(*******************************  doganii  *)

Needs["Splines`"]

doganii[1]={{0.669,50.2006},{3.347,49.5313},{6.024,46.8539},{8.701,46.1846},{11.379,43.5072},{14.056,43.5072},{16.734,44.8459},{19.411,46.1846},{22.088,49.5313},{24.766,53.5473},{27.443,54.8860},{30.120,56.8940},{32.798,58.2327},{35.475,60.2407},{38.152,61.5794},{40.830,62.2488},{43.507,60.9101},{46.185,62.9181},{48.862,64.2568},{51.539,64.2568},{54.217,64.2568},{56.894,64.9261},{59.571,64.2568},{62.249,64.2568},{64.926,63.5875},{67.604,62.2488},{70.281,62.2488},{72.958,60.9101},{75.636,60.9101},{78.313,59.5714},{80.990,59.5714},{83.668,58.2327},{86.345,57.5634},{89.022,53.5473},{91.700,51.5393},{94.377,50.2006},{97.055,48.8619},{99.732,47.5233},{102.409,43.5072},{105.087,42.1685},{107.764,40.1605},{110.441,38.1525},{113.119,37.4831},{115.796,34.8058},{118.473,34.8058},{121.151,35.4751},{123.828,34.8058},{126.506,40.1605},{129.183,41.4992},{131.860,46.8539},{134.538,48.1926},{137.215,52.2086},{139.892,55.5554},{142.570,57.5634},{145.247,58.9021},{147.924,60.2407},{150.602,62.2488},{153.279,64.2568},{155.957,65.5955},{158.634,66.2648},{161.311,66.2648},{163.989,66.9342},{166.666,67.6035},{169.343,66.2648},{172.021,65.5955},{174.698,65.5955},{177.376,66.2648},{180.053,66.2648},{182.730,65.5955},{185.408,64.9261},{188.085,64.2568},{190.762,61.5794},{193.440,60.9101},{196.117,58.2327},{198.794,56.8940},{201.472,55.5554},{204.149,51.5393},{206.827,47.5233},{209.504,44.8459},{212.181,44.1765},{214.859,39.4912},{217.536,36.1444},{220.213,36.1444},{222.891,38.1525},{225.568,40.1605},{228.245,44.1765}}
doganii[2]={{0.669,22.0883},{3.347,22.7576},{6.024,23.4270},{8.701,26.1043},{11.379,30.1204},{14.056,32.7977},{16.734,34.1364},{19.411,34.8058},{22.088,37.4831},{24.766,39.4912},{27.443,40.8298},{30.120,41.4992},{32.798,42.1685},{35.475,43.5072},{38.152,44.1765},{40.830,44.1765},{43.507,42.1685},{46.185,43.5072},{48.862,42.8379},{51.539,42.1685},{54.217,42.1685},{56.894,40.8298},{59.571,39.4912},{62.249,38.1525},{64.926,36.8138},{67.604,35.4751},{70.281,34.1364},{72.958,32.7977},{75.636,31.4591},{78.313,29.4510},{80.990,28.1123},{83.668,28.1123},{86.345,29.4510},{89.022,30.1204},{91.700,31.4591},{94.377,32.1284},{97.055,33.4671},{99.732,36.8138},{102.409,38.1525},{105.087,38.8218},{107.764,39.4912},{110.441,40.8298},{113.119,42.1685},{115.796,42.1685},{118.473,43.5072},{121.151,44.1765},{123.828,44.8459},{126.506,46.1846},{129.183,46.8539},{131.860,47.5233},{134.538,47.5233},{137.215,46.1846},{139.892,46.8539},{142.570,46.1846},{145.247,44.8459},{147.924,43.5072},{150.602,42.1685},{153.279,40.8298},{155.957,39.4912},{158.634,37.4831},{161.311,36.8138},{163.989,34.8058},{166.666,34.1364},{169.343,29.4510},{172.021,28.1123},{174.698,30.1204},{177.376,29.4510}}
doganii[3]={{0.669,38.1525},{3.347,38.1525},{6.024,38.1525},{8.701,37.4831},{11.379,38.1525},{14.056,39.4912},{16.734,40.1605},{19.411,41.4992},{22.088,42.1685},{24.766,46.1846},{27.443,47.5233},{30.120,48.8619},{32.798,49.5313},{35.475,53.5473},{38.152,54.8860},{40.830,55.5554},{43.507,56.8940},{46.185,58.2327},{48.862,58.9021},{51.539,59.5714},{54.217,60.9101},{56.894,59.5714},{59.571,59.5714},{62.249,59.5714},{64.926,58.9021},{67.604,58.2327},{70.281,58.2327},{72.958,56.8940},{75.636,56.2247},{78.313,54.8860},{80.990,53.5473},{83.668,52.2086},{86.345,51.5393},{89.022,51.5393},{91.700,49.5313},{94.377,42.1685},{97.055,39.4912},{99.732,38.1525},{102.409,39.4912},{105.087,40.8298},{107.764,42.1685},{110.441,42.8379},{113.119,43.5072},{115.796,44.8459},{118.473,46.1846},{121.151,47.5233},{123.828,51.5393},{126.506,52.2086},{129.183,52.8780},{131.860,54.2167},{134.538,55.5554},{137.215,56.2247},{139.892,56.8940},{142.570,59.5714},{145.247,62.2488},{147.924,63.5875},{150.602,63.5875},{153.279,62.2488},{155.957,62.9181},{158.634,63.5875},{161.311,64.9261},{163.989,64.9261},{166.666,63.5875},{169.343,63.5875},{172.021,64.2568},{174.698,62.2488},{177.376,61.5794},{180.053,60.2407},{182.730,58.2327},{185.408,59.5714},{188.085,58.2327},{190.762,54.8860},{193.440,47.5233},{193.440,52.2086},{196.117,46.8539},{198.794,49.5313},{201.472,49.5313},{204.149,43.5072},{206.827,41.4992},{209.504,36.8138},{212.181,36.1444},{214.859,35.4751},{217.536,34.1364},{220.213,36.1444},{222.891,38.1525},{225.568,38.1525},{228.245,38.1525}}
doganii[4]={{0.669,32.1284},{3.347,32.7977},{6.024,30.7897},{8.701,30.7897},{8.701,35.4751},{11.379,36.8138},{14.056,36.8138},{16.734,36.8138},{19.411,36.1444},{22.088,34.1364},{24.766,38.8218},{27.443,40.8298},{30.120,38.1525},{32.798,40.1605},{35.475,44.8459},{38.152,48.8619},{40.830,48.1926},{43.507,50.2006},{46.185,50.2006},{48.862,51.5393},{51.539,53.5473},{54.217,56.2247},{56.894,56.8940},{59.571,57.5634},{62.249,58.9021},{64.926,59.5714},{67.604,60.2407},{70.281,61.5794},{72.958,60.9101},{75.636,60.9101},{78.313,61.5794},{80.990,63.5875},{83.668,62.9181},{86.345,62.9181},{89.022,61.5794},{91.700,60.9101},{94.377,58.2327},{97.055,56.2247},{99.732,58.9021},{102.409,60.2407},{105.087,55.5554},{107.764,57.5634},{110.441,55.5554},{113.119,52.8780},{115.796,51.5393},{118.473,48.1926},{121.151,48.1926},{123.828,50.8700},{126.506,47.5233},{129.183,46.8539},{131.860,48.1926},{134.538,41.4992},{137.215,38.8218},{139.892,38.1525},{142.570,37.4831},{145.247,35.4751},{147.924,36.1444},{150.602,34.1364},{153.279,34.1364},{155.957,33.4671},{158.634,32.7977},{161.311,33.4671},{163.989,35.4751},{166.666,37.4831},{169.343,40.8298},{172.021,42.1685},{174.698,42.1685},{177.376,44.1765},{180.053,44.8459},{182.730,44.8459},{185.408,44.1765},{188.085,49.5313},{190.762,51.5393},{193.440,51.5393},{196.117,52.2086},{198.794,53.5473},{201.472,53.5473},{204.149,52.8780},{206.827,50.8700},{209.504,55.5554},{212.181,55.5554},{214.859,55.5554},{217.536,55.5554},{220.213,54.8860},{222.891,54.8860},{225.568,54.2167},{228.245,54.8860},{230.923,50.2006},{233.600,52.2086},{236.278,50.2006},{238.955,47.5233},{241.632,46.1846},{244.310,42.8379},{246.987,42.8379},{249.664,44.8459},{252.342,41.4992},{255.019,36.8138},{257.697,35.4751},{260.374,35.4751},{263.051,31.4591},{265.729,28.7817},{268.406,27.4430},{271.083,28.1123},{273.761,26.7737},{276.438,26.7737},{279.115,28.1123},{281.793,28.1123},{284.470,28.7817},{287.148,26.7737}}

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