(*******************************  cephalantha  *)

Needs["Splines`"]

cephalantha[1]={{0.826,21.4869},{4.132,19.0076},{7.438,17.3548},{10.743,16.5284},{14.049,16.5284},{17.355,15.7019},{20.660,17.3548},{23.966,21.4869},{27.272,24.7925},{30.577,26.4454},{33.883,29.7511},{37.189,33.0567},{40.494,35.5360},{43.800,38.0152},{47.106,38.8416},{50.412,41.3209},{53.717,42.9737},{57.023,42.9737},{60.329,43.8002},{63.634,45.4530},{66.940,45.4530},{70.246,45.4530},{73.551,45.4530},{76.857,44.6266},{80.163,43.8002},{83.468,42.9737},{86.774,42.1473},{90.080,40.4945},{93.385,38.8416},{96.691,37.1888},{99.997,34.7096},{103.302,28.9246},{106.608,25.6190},{109.914,20.6605},{113.219,19.8340},{116.525,23.9661},{119.831,29.7511},{123.136,33.0567},{126.442,36.3624},{129.748,38.0152},{133.053,41.3209},{136.359,43.8002},{139.665,46.2794},{142.970,49.5851},{146.276,50.4115},{149.582,52.0643},{152.887,52.0643},{156.193,50.4115},{159.499,50.4115},{162.804,50.4115},{166.110,50.4115},{169.416,48.7587},{172.721,48.7587},{176.027,48.7587},{179.333,47.1058},{182.638,43.8002},{185.944,41.3209},{189.250,39.6681},{192.555,36.3624},{195.861,34.7096},{199.167,29.7511},{202.472,27.2718},{205.778,22.3133},{209.084,19.8340},{212.389,17.3548},{215.695,21.4869},{219.001,23.9661},{222.306,25.6190},{225.612,28.0982}}
cephalantha[2]={{0.826,5.7849},{4.132,5.7849},{7.438,5.7849},{10.743,5.7849},{14.049,12.3963},{17.355,19.0076},{20.660,24.7925},{23.966,28.9246},{27.272,33.0567},{30.577,36.3624},{33.883,38.0152},{37.189,41.3209},{40.494,42.9737},{43.800,44.6266},{47.106,45.4530},{50.412,45.4530},{53.717,47.1058},{57.023,46.2794},{60.329,45.4530},{63.634,46.2794},{66.940,45.4530},{70.246,45.4530},{73.551,42.9737},{76.857,42.1473},{80.163,39.6681},{83.468,38.0152},{86.774,35.5360},{90.080,33.8831},{93.385,32.2303},{96.691,28.9246},{99.997,24.7925},{103.302,23.1397},{106.608,29.7511},{109.914,33.0567},{113.219,35.5360},{116.525,37.1888},{119.831,39.6681},{123.136,42.1473},{126.442,44.6266},{129.748,46.2794},{133.053,49.5851},{136.359,51.2379},{139.665,52.0643},{142.970,52.0643},{146.276,52.8908},{149.582,53.7172},{152.887,53.7172},{156.193,53.7172},{159.499,53.7172},{162.804,52.0643},{166.110,52.0643},{169.416,50.4115},{172.721,48.7587},{176.027,46.2794},{179.333,44.6266},{182.638,42.9737},{185.944,39.6681},{189.250,38.0152},{192.555,34.7096},{195.861,33.0567},{199.167,31.4039},{202.472,28.9246},{205.778,26.4454},{209.084,28.0982},{212.389,30.5775}}
cephalantha[3]={{0.826,15.7019},{4.132,15.7019},{7.438,14.8755},{10.743,19.0076},{14.049,22.3133},{17.355,26.4454},{20.660,30.5775},{23.966,34.7096},{27.272,37.1888},{30.577,39.6681},{33.883,42.1473},{37.189,42.9737},{40.494,45.4530},{43.800,46.2794},{47.106,45.4530},{50.412,47.1058},{53.717,47.1058},{57.023,47.1058},{60.329,46.2794},{63.634,45.4530},{66.940,45.4530},{70.246,44.6266},{73.551,43.8002},{76.857,43.8002},{80.163,42.1473},{83.468,42.1473},{86.774,38.8416},{90.080,32.2303},{93.385,28.0982},{96.691,23.9661},{99.997,22.3133},{103.302,28.0982},{106.608,29.7511},{109.914,31.4039},{113.219,33.8831},{116.525,35.5360},{119.831,37.1888},{123.136,38.8416},{126.442,39.6681},{129.748,40.4945},{133.053,40.4945},{136.359,40.4945},{139.665,40.4945},{142.970,40.4945},{146.276,39.6681},{149.582,38.8416},{152.887,37.1888},{156.193,35.5360},{159.499,33.8831},{162.804,31.4039},{166.110,28.0982},{169.416,24.7925},{172.721,21.4869},{176.027,18.1812},{179.333,14.8755},{182.638,9.9170},{185.944,7.4378},{189.250,7.4378},{192.555,7.4378},{195.861,7.4378}}

(*Poner aqui la familia*)
var=cephalantha;
(* el número de curvas estudiadas/semillas de la familia*)
m=3;
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,3}]];
Print["Valores medios de curvatura de cada ", var ," en [0,1]:  ", Table[vmed[j],{j,1,3}]];

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