(*******************************  bupleuroides  *)

Needs["Splines`"]

bupleuroides[1]={{0.521,24.9997},{2.604,21.8747},{4.687,20.8331},{6.771,19.2706},{8.854,16.6664},{10.937,17.1873},{13.021,17.1873},{15.104,16.6664},{17.187,16.1456},{19.271,17.1873},{21.354,18.7497},{23.437,24.4788},{25.520,30.7288},{27.604,35.4162},{29.687,36.9787},{31.770,39.0620},{33.854,41.1453},{35.937,42.7078},{38.020,43.2286},{40.104,42.7078},{42.187,43.2286},{44.270,42.7078},{46.354,42.1869},{48.437,43.7494},{50.520,44.7911},{52.603,46.3535},{54.687,46.3535},{56.770,45.8327},{58.853,46.8744},{60.937,46.8744},{63.020,46.8744},{65.103,48.4368},{67.187,47.9160},{69.270,48.4368},{71.353,47.3952},{73.437,47.3952},{75.520,47.3952},{77.603,47.3952},{79.686,46.8744},{81.770,45.3119},{83.853,44.2702},{85.936,43.7494},{88.020,42.7078},{90.103,40.1036},{92.186,39.5828},{94.270,36.9787},{96.353,35.4162},{98.436,32.2912},{100.519,30.7288},{102.603,28.1246},{104.686,27.0830},{106.769,26.5621},{108.853,23.9580},{110.936,24.9997},{113.019,26.5621},{115.103,29.1663},{117.186,32.8121},{119.269,33.8537},{121.353,37.4995},{123.436,39.0620},{125.519,39.0620},{127.602,41.6661},{129.686,43.7494},{131.769,44.7911},{133.852,45.3119},{135.936,45.3119},{138.019,45.8327},{140.102,46.8744},{142.186,46.3535},{144.269,46.8744},{146.352,48.4368},{148.435,49.4785},{150.519,49.4785},{152.602,49.4785},{154.685,48.4368},{156.769,48.4368},{158.852,47.3952},{160.935,47.3952},{163.019,45.3119},{165.102,44.7911},{167.185,44.2702},{169.269,42.7078},{171.352,41.1453},{173.435,39.0620},{175.518,36.4578},{177.602,35.4162},{179.685,30.7288},{181.768,28.6454},{183.852,23.4372},{185.935,17.1873},{188.018,17.7081},{190.102,19.2706},{192.185,21.8747},{194.268,25.5205},{196.352,26.5621},{198.435,29.1663},{200.518,30.7288},{202.601,31.7704},{204.685,34.8954},{206.768,35.4162},{208.851,35.4162},{210.935,35.4162},{213.018,34.8954}}
bupleuroides[2]={{0.521,18.7497},{2.604,17.7081},{4.687,16.1456},{6.771,15.1040},{8.854,14.0623},{10.937,11.4582},{13.021,9.3749},{15.104,9.3749},{17.187,11.4582},{19.271,15.1040},{21.354,18.2289},{23.437,20.3122},{25.520,22.3955},{27.604,23.9580},{29.687,24.9997},{31.770,27.6038},{33.854,28.6454},{35.937,29.6871},{38.020,30.7288},{40.104,30.7288},{42.187,33.8537},{44.270,37.4995},{46.354,38.0203},{48.437,36.9787},{50.520,37.4995},{52.603,38.5411},{54.687,39.0620},{56.770,38.5411},{58.853,39.5828},{60.937,39.0620},{63.020,39.5828},{65.103,40.6245},{67.187,40.6245},{69.270,41.1453},{71.353,41.1453},{73.437,41.1453},{75.520,41.1453},{77.603,41.1453},{79.686,40.1036},{81.770,40.6245},{83.853,41.1453},{85.936,41.1453},{88.020,39.5828},{90.103,37.4995},{92.186,36.4578},{94.270,33.3329},{96.353,32.2912},{98.436,29.1663},{100.519,26.0413},{102.603,22.9164},{104.686,22.3955},{106.769,24.9997},{108.853,27.0830},{110.936,29.6871},{113.019,30.7288},{115.103,32.2912},{117.186,32.8121},{119.269,33.8537},{121.353,34.8954},{123.436,34.8954},{125.519,36.4578},{127.602,36.4578},{129.686,35.4162},{131.769,36.9787},{133.852,36.9787},{135.936,34.3745},{138.019,33.3329},{140.102,34.3745},{142.186,35.9370},{144.269,35.9370},{146.352,33.3329},{148.435,31.7704},{150.519,30.7288},{152.602,28.6454},{154.685,24.9997},{156.769,22.3955},{158.852,13.5415},{158.852,19.2706},{160.935,10.9374},{163.019,10.4165},{165.102,13.5415},{167.185,20.8331},{169.269,23.9580},{171.352,25.5205}}
bupleuroides[3]={{0.521,4.1666},{2.604,1.0417},{4.687,0.5208},{6.771,1.5625},{6.771,11.9790},{6.771,15.6248},{6.771,20.8331},{6.771,26.5621},{8.854,2.6041},{8.854,7.8124},{8.854,28.6454},{10.937,33.3329},{13.021,34.3745},{15.104,34.8954},{17.187,36.4578},{19.271,37.4995},{21.354,38.5411},{23.437,40.1036},{25.520,41.1453},{27.604,41.1453},{29.687,41.1453},{31.770,42.1869},{33.854,41.1453},{35.937,42.1869},{38.020,41.1453},{40.104,41.1453},{42.187,41.1453},{44.270,41.1453},{46.354,40.1036},{48.437,39.5828},{50.520,39.0620},{52.603,39.0620},{54.687,38.5411},{56.770,37.4995},{58.853,36.4578},{60.937,35.4162},{63.020,33.8537},{65.103,32.2912},{67.187,30.2079},{69.270,28.6454},{71.353,25.5205},{73.437,21.3539},{75.520,18.2289},{77.603,16.1456},{79.686,16.1456},{81.770,20.8331},{81.770,29.1663},{83.853,30.2079},{83.853,34.3745},{85.936,36.4578},{88.020,37.4995},{90.103,38.5411},{92.186,39.5828},{94.270,40.1036},{96.353,40.1036},{98.436,40.6245},{100.519,41.1453},{102.603,40.1036},{104.686,41.1453},{106.769,40.6245},{108.853,40.6245},{110.936,40.1036},{113.019,40.1036},{115.103,39.5828},{117.186,39.0620},{119.269,38.0203},{121.353,37.4995},{123.436,36.4578},{125.519,34.3745},{127.602,32.8121},{129.686,31.2496},{131.769,27.0830},{133.852,27.0830},{133.852,31.2496},{135.936,28.6454},{135.936,35.4162},{138.019,38.0203}}
bupleuroides[4]={{0.521,13.5415},{2.604,11.9790},{4.687,7.8124},{6.771,3.1250},{8.854,2.6041},{10.937,3.6458},{10.937,8.8540},{13.021,14.0623},{15.104,19.7914},{17.187,23.4372},{19.271,24.9997},{21.354,27.0830},{23.437,29.1663},{25.520,30.2079},{27.604,31.7704},{29.687,33.3329},{31.770,33.8537},{33.854,33.8537},{35.937,34.8954},{38.020,35.9370},{40.104,35.9370},{42.187,35.9370},{44.270,35.9370},{46.354,35.9370},{48.437,35.4162},{50.520,34.8954},{52.603,33.8537},{54.687,33.8537},{56.770,32.2912},{58.853,31.7704},{60.937,30.7288},{63.020,29.1663},{65.103,28.1246},{67.187,27.0830},{69.270,25.5205},{71.353,21.3539},{73.437,19.2706},{73.437,21.8747},{75.520,20.8331},{77.603,22.3955},{79.686,23.4372},{81.770,23.4372},{83.853,26.0413},{85.936,27.6038},{88.020,29.1663},{90.103,30.2079},{92.186,31.7704},{94.270,32.2912},{96.353,33.8537},{98.436,34.8954},{100.519,35.9370},{102.603,35.9370},{104.686,36.4578},{106.769,37.4995},{108.853,37.4995},{110.936,37.4995},{113.019,38.0203},{115.103,38.0203},{117.186,39.0620},{119.269,39.0620},{121.353,39.0620},{123.436,40.1036},{125.519,39.5828},{127.602,39.5828},{129.686,39.5828},{131.769,39.0620},{133.852,39.0620},{135.936,38.0203},{138.019,38.0203},{140.102,39.0620},{142.186,39.5828},{144.269,38.0203},{146.352,38.5411},{148.435,38.0203},{150.519,37.4995},{152.602,35.9370},{154.685,34.8954},{156.769,34.3745},{158.852,35.9370},{160.935,34.8954},{163.019,31.2496},{165.102,28.1246},{167.185,27.6038},{169.269,28.6454},{171.352,28.6454},{173.435,28.6454},{175.518,30.7288}}

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