(*******************************  birandiana  *)

Needs["Splines`"]

birandiana[1]={{1.053,43.1579},{5.263,41.0526},{9.474,36.8421},{13.684,38.9474},{17.895,44.2105},{22.105,49.4737},{26.316,50.5263},{30.526,54.7368},{34.737,55.7895},{38.947,57.8947},{43.158,57.8947},{47.368,57.8947},{51.579,56.8421},{55.789,54.7368},{60.000,50.5263},{64.211,48.4211},{68.421,43.1579},{72.632,41.0526},{76.842,33.6842},{81.053,30.5263},{85.263,33.6842},{89.474,35.7895},{93.684,38.9474},{97.895,47.3684},{102.105,49.4737},{106.316,49.4737},{110.526,49.4737},{114.737,49.4737},{118.947,50.5263},{123.158,49.4737},{127.368,51.5789},{131.579,48.4211},{135.789,43.1579},{140.000,38.9474},{144.211,32.6316},{148.421,28.4211},{152.632,25.2632},{156.842,24.2105},{161.053,25.2632},{165.263,28.4211},{169.474,31.5789}}
birandiana[2]={{1.053,31.5789},{5.263,29.4737},{9.474,31.5789},{13.684,35.7895},{17.895,38.9474},{22.105,42.1053},{26.316,43.1579},{30.526,44.2105},{34.737,43.1579},{38.947,43.1579},{43.158,40.0000},{47.368,37.8947},{51.579,33.6842},{55.789,31.5789},{60.000,28.4211},{64.211,27.3684},{68.421,24.2105},{72.632,24.2105},{76.842,26.3158},{81.053,27.3684},{85.263,28.4211},{89.474,30.5263},{93.684,32.6316},{97.895,32.6316},{102.105,32.6316},{106.316,31.5789},{110.526,29.4737},{114.737,27.3684},{118.947,23.1579},{123.158,20.0000},{127.368,14.7368},{131.579,11.5789},{135.789,11.5789},{140.000,12.6316}}
birandiana[3]={{1.053,8.4211},{5.263,7.3684},{9.474,7.3684},{13.684,1.0526},{13.684,11.5789},{17.895,10.5263},{22.105,11.5789},{26.316,12.6316},{30.526,13.6842},{34.737,14.7368},{38.947,14.7368},{43.158,15.7895},{47.368,15.7895},{51.579,15.7895},{55.789,15.7895},{60.000,14.7368},{64.211,13.6842},{68.421,11.5789},{72.632,10.5263},{76.842,8.4211},{81.053,8.4211},{85.263,7.3684},{89.474,8.4211},{93.684,8.4211},{97.895,9.4737},{102.105,11.5789},{106.316,11.5789},{110.526,12.6316},{114.737,13.6842},{118.947,13.6842},{123.158,13.6842},{127.368,12.6316},{131.579,11.5789},{135.789,9.4737},{140.000,7.3684},{144.211,4.2105},{148.421,3.1579},{152.632,1.0526},{156.842,1.0526},{161.053,1.0526}}
birandiana[4]={{1.053,27.3684},{5.263,27.3684},{9.474,26.3158},{13.684,27.3684},{17.895,29.4737},{22.105,33.6842},{26.316,38.9474},{30.526,42.1053},{34.737,44.2105},{38.947,47.3684},{43.158,47.3684},{47.368,47.3684},{51.579,47.3684},{55.789,47.3684},{60.000,47.3684},{64.211,46.3158},{68.421,44.2105},{72.632,42.1053},{76.842,37.8947},{81.053,34.7368},{85.263,33.6842},{89.474,31.5789},{93.684,30.5263},{97.895,31.5789},{102.105,33.6842},{106.316,36.8421},{110.526,40.0000},{114.737,42.1053},{118.947,44.2105},{123.158,45.2632},{127.368,47.3684},{131.579,47.3684},{135.789,47.3684},{140.000,47.3684},{144.211,45.2632},{148.421,45.2632},{152.632,43.1579},{156.842,42.1053},{161.053,38.9474},{165.263,36.8421},{169.474,36.8421},{173.684,33.6842},{177.895,26.3158},{182.105,21.0526},{186.316,15.7895},{190.526,13.6842}}

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