(*******************************  rhynchocarpa  *)

Needs["Splines`"]

rhynchocarpa[1]={{15.184,0.3703},{16.666,1.1110},{18.147,1.8517},{19.628,2.2221},{21.110,2.5924},{22.591,3.3331},{24.073,4.4442},{25.554,5.9256},{27.035,7.4069},{28.517,9.2587},{29.998,11.8511},{31.480,14.0732},{32.961,16.2953},{34.442,17.7767},{35.924,19.2581},{37.405,19.9988},{38.886,21.4802},{40.368,22.9615},{41.849,24.4429},{43.331,25.5540},{44.812,25.9243},{46.293,27.0354},{47.775,27.7761},{49.256,28.8871},{50.738,29.2575},{52.219,29.9981},{53.700,30.3685},{55.182,30.7388},{56.663,31.4795},{58.145,32.2202},{59.626,32.5906},{61.107,32.9609},{62.589,32.9609},{64.070,33.7016},{65.552,34.0720},{67.033,34.4423},{68.514,35.1830},{69.996,35.1830},{71.477,35.1830},{72.958,35.5534},{74.440,35.9237},{75.921,35.9237},{77.403,36.6644},{78.884,36.6644},{80.365,36.6644},{81.847,37.0348},{83.328,37.4051},{84.810,37.4051},{86.291,36.6644},{87.772,36.6644},{89.254,37.0348},{90.735,36.6644},{92.217,36.6644},{93.698,35.9237},{95.179,35.9237},{96.661,35.5534},{98.142,35.1830},{99.623,35.1830},{101.105,34.4423},{102.586,34.0720},{104.068,33.7016},{105.549,32.9609},{107.030,32.2202},{108.512,32.2202},{109.993,31.4795},{111.475,31.4795},{112.956,31.1092},{114.437,30.7388},{115.919,30.7388},{117.400,30.7388},{118.882,30.7388},{120.363,31.1092},{121.844,31.8499},{123.326,32.5906},{124.807,33.3313},{126.288,34.4423},{127.770,35.5534},{129.251,37.0348},{130.733,38.8865},{132.214,40.7382},{133.695,42.2196},{135.177,43.7010},{136.658,45.1824},{138.140,45.9231},{139.621,47.4045},{141.102,48.5155},{142.584,49.6266},{144.065,50.3673},{145.547,50.7376},{147.028,51.4783},{148.509,52.2190},{149.991,52.9597},{151.472,52.9597},{152.954,53.3300},{154.435,53.7004},{155.916,53.7004},{157.398,54.4411},{158.879,54.4411},{160.360,54.4411},{161.842,55.1818},{163.323,55.1818},{164.805,55.1818},{166.286,55.1818},{167.767,55.9225},{169.249,55.9225},{170.730,56.6632},{172.212,56.6632},{173.693,56.6632},{175.174,56.6632},{176.656,57.0335},{178.137,57.0335},{179.619,57.4039},{181.100,57.4039},{182.581,57.4039},{184.063,57.4039},{185.544,57.4039},{187.025,57.4039},{188.507,57.4039},{189.988,57.4039},{191.470,57.4039},{192.951,56.6632},{194.432,56.6632},{195.914,56.2928},{197.395,55.9225},{198.877,54.8114},{200.358,54.0707},{201.839,53.3300},{203.321,51.8487},{204.802,51.1080},{206.284,49.9969},{207.765,49.2562},{209.246,48.5155},{210.728,47.7748},{212.209,47.0341},{213.691,46.2934},{215.172,45.5527},{216.653,45.5527},{218.135,44.8120},{219.616,45.1824},{221.097,45.5527},{222.579,45.9231}}
rhynchocarpa[2]={{0.370,28.5168},{1.852,28.1464},{3.333,27.7761},{4.815,28.5168},{6.296,28.5168},{7.777,29.6278},{9.259,30.3685},{10.740,32.5906},{12.221,34.0720},{13.703,35.5534},{15.184,36.2941},{16.666,37.7754},{18.147,38.5161},{19.628,39.6272},{21.110,40.3679},{22.591,41.1086},{24.073,41.4789},{25.554,41.8493},{27.035,42.9603},{28.517,43.7010},{29.998,44.0714},{31.480,44.4417},{32.961,44.8120},{34.442,45.5527},{35.924,45.5527},{37.405,45.5527},{38.886,45.9231},{40.368,46.2934},{41.849,46.2934},{43.331,46.2934},{44.812,46.6638},{46.293,47.0341},{47.775,47.0341},{49.256,47.0341},{50.738,47.0341},{52.219,47.0341},{53.700,47.0341},{55.182,47.0341},{56.663,47.0341},{58.145,47.0341},{59.626,46.2934},{61.107,46.2934},{62.589,46.2934},{64.070,46.2934},{65.552,46.2934},{67.033,45.5527},{68.514,45.1824},{69.996,44.8120},{71.477,44.0714},{72.958,43.7010},{74.440,43.3307},{75.921,42.5900},{77.403,42.2196},{78.884,41.8493},{80.365,40.7382},{81.847,39.9975},{83.328,39.6272},{84.810,38.8865},{86.291,37.7754},{87.772,37.0348},{89.254,35.9237},{90.735,35.1830},{92.217,34.4423},{93.698,33.7016},{95.179,33.3313},{96.661,32.2202},{98.142,31.4795},{99.623,31.1092},{101.105,30.7388},{102.586,30.3685},{104.068,29.9981},{105.549,29.9981},{107.030,29.9981},{108.512,30.7388},{109.993,30.7388},{111.475,31.4795},{112.956,32.2202},{114.437,32.5906},{115.919,33.3313},{117.400,34.4423},{118.882,35.1830},{120.363,35.9237},{121.844,36.6644},{123.326,36.6644},{124.807,37.4051},{126.288,37.4051},{127.770,37.4051},{129.251,38.1458},{130.733,38.8865},{132.214,38.1458},{133.695,38.8865},{135.177,38.8865},{136.658,38.8865},{138.140,38.8865},{139.621,38.8865},{141.102,38.8865},{142.584,38.8865},{144.065,38.1458},{145.547,38.1458},{147.028,38.1458},{148.509,38.1458},{149.991,38.1458},{151.472,38.1458},{152.954,38.1458},{154.435,38.1458},{155.916,38.1458},{157.398,37.4051},{158.879,37.4051},{160.360,37.4051},{161.842,37.4051},{163.323,37.4051},{164.805,37.4051},{166.286,37.4051},{167.767,37.4051},{169.249,36.6644},{170.730,36.6644},{172.212,35.9237},{173.693,35.9237},{175.174,35.9237},{176.656,35.1830},{178.137,34.4423},{179.619,34.4423},{181.100,34.0720},{182.581,33.3313},{184.063,32.5906},{185.544,31.8499},{187.025,31.1092},{188.507,29.6278},{189.988,28.1464},{191.470,25.9243},{192.951,24.4429},{194.432,22.5912},{195.914,21.8505},{197.395,21.1098},{198.877,20.3691},{200.358,20.3691},{201.839,20.7395},{203.321,21.1098},{204.802,21.4802}}
rhynchocarpa[3]={{0.370,14.0732},{1.852,12.5918},{3.333,11.1104},{4.815,9.6290},{6.296,9.2587},{7.777,9.6290},{9.259,11.1104},{10.740,12.9622},{12.221,14.8139},{13.703,17.4063},{15.184,18.5174},{16.666,19.2581},{18.147,20.7395},{19.628,21.8505},{21.110,22.2208},{22.591,22.9615},{24.073,23.7022},{25.554,24.4429},{27.035,25.1836},{28.517,25.5540},{29.998,26.2947},{31.480,26.2947},{32.961,26.2947},{34.442,26.2947},{35.924,26.6650},{37.405,27.0354},{38.886,27.0354},{40.368,27.4057},{41.849,27.7761},{43.331,28.1464},{44.812,28.5168},{46.293,28.5168},{47.775,28.5168},{49.256,29.2575},{50.738,29.2575},{52.219,29.2575},{53.700,29.2575},{55.182,29.2575},{56.663,29.9981},{58.145,29.9981},{59.626,29.9981},{61.107,29.9981},{62.589,29.9981},{64.070,29.9981},{65.552,29.9981},{67.033,29.6278},{68.514,28.8871},{69.996,28.1464},{71.477,27.4057},{72.958,25.9243},{74.440,24.8133},{75.921,22.9615},{77.403,22.5912},{78.884,21.4802},{80.365,20.7395},{81.847,19.9988},{83.328,19.6284},{84.810,20.3691},{86.291,21.1098},{87.772,21.4802},{89.254,22.5912},{90.735,23.7022},{92.217,24.4429},{93.698,26.2947},{95.179,28.1464},{96.661,30.3685},{98.142,31.8499},{99.623,33.7016},{101.105,35.5534},{102.586,36.2941},{104.068,36.6644},{105.549,37.0348},{107.030,37.4051},{108.512,38.1458},{109.993,38.1458},{111.475,38.5161},{112.956,38.8865},{114.437,38.8865},{115.919,39.2568},{117.400,39.6272},{118.882,39.9975},{120.363,40.3679},{121.844,40.3679},{123.326,40.3679},{124.807,41.1086},{126.288,41.1086},{127.770,41.1086},{129.251,41.1086},{130.733,41.1086},{132.214,41.1086},{133.695,41.1086},{135.177,41.1086},{136.658,41.1086},{138.140,40.7382},{139.621,40.3679},{141.102,40.3679},{142.584,40.3679},{144.065,39.9975},{145.547,39.2568},{147.028,38.8865},{148.509,38.5161},{149.991,37.4051},{151.472,35.9237},{152.954,34.8127},{154.435,33.3313},{155.916,32.5906},{157.398,31.4795},{158.879,30.3685},{160.360,29.9981},{161.842,29.2575},{163.323,29.2575},{164.805,29.2575},{166.286,29.2575},{167.767,29.2575},{169.249,29.2575},{170.730,29.9981},{172.212,29.9981},{173.693,29.9981}}
rhynchocarpa[4]={{0.370,19.2581},{1.852,18.8877},{3.333,18.8877},{4.815,18.8877},{6.296,18.8877},{7.777,18.8877},{9.259,19.2581},{10.740,19.6284},{12.221,19.6284},{13.703,19.6284},{15.184,20.7395},{16.666,22.5912},{18.147,24.4429},{19.628,25.1836},{21.110,25.9243},{22.591,27.0354},{24.073,28.1464},{25.554,28.5168},{27.035,29.2575},{28.517,29.9981},{29.998,30.7388},{31.480,30.7388},{32.961,31.4795},{34.442,31.4795},{35.924,31.8499},{37.405,32.2202},{38.886,32.2202},{40.368,32.5906},{41.849,32.5906},{43.331,32.2202},{44.812,32.2202},{46.293,32.2202},{47.775,32.2202},{49.256,32.2202},{50.738,31.4795},{52.219,31.4795},{53.700,31.1092},{55.182,30.7388},{56.663,29.6278},{58.145,28.8871},{59.626,28.5168},{61.107,27.4057},{62.589,25.5540},{64.070,24.4429},{65.552,22.9615},{67.033,21.4802},{68.514,19.9988},{69.996,18.5174},{71.477,17.7767},{72.958,17.4063},{74.440,17.4063},{75.921,17.7767},{77.403,18.5174},{78.884,19.6284},{80.365,20.7395},{81.847,21.4802},{83.328,22.5912},{84.810,23.3319},{86.291,23.7022},{87.772,24.0726},{89.254,25.1836},{90.735,25.5540},{92.217,26.2947},{93.698,26.6650},{95.179,27.0354},{96.661,27.0354},{98.142,27.7761},{99.623,27.7761},{101.105,27.7761},{102.586,27.7761},{104.068,27.7761},{105.549,27.7761},{107.030,28.5168},{108.512,28.5168},{109.993,28.5168},{111.475,28.5168},{112.956,28.5168},{114.437,28.5168},{115.919,28.1464},{117.400,27.7761},{118.882,27.4057},{120.363,27.0354},{121.844,27.0354},{123.326,26.2947},{124.807,25.9243},{126.288,25.1836},{127.770,24.8133},{129.251,24.0726},{130.733,22.9615},{132.214,21.8505},{133.695,20.7395},{135.177,19.6284},{136.658,18.5174},{138.140,17.4063},{139.621,15.5546},{141.102,13.7029},{142.584,11.8511},{144.065,9.6290},{145.547,7.0366},{147.028,5.1849},{148.509,4.8145},{149.991,5.5552},{151.472,6.6663},{152.954,8.5180},{154.435,9.6290},{155.916,10.7401},{157.398,11.1104}}

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