(*******************************  reinwardtii  *)

Needs["Splines`"]

reinwardtii[1]={{0.434,30.8276},{2.171,30.3934},{3.908,29.5251},{5.644,28.2225},{7.381,26.9199},{9.118,25.6173},{10.855,23.8806},{12.592,22.1438},{14.328,21.7096},{16.065,23.4464},{16.065,26.9199},{17.802,29.5251},{19.539,35.6037},{21.275,41.2482},{23.012,44.2876},{23.012,50.3663},{24.749,53.8398},{26.486,57.3134},{28.222,60.3527},{29.959,64.2604},{31.696,68.6023},{33.433,71.2075},{35.170,73.8126},{36.906,77.7204},{38.643,82.4965},{40.380,83.3649},{42.117,85.1016},{43.853,89.0094},{45.590,91.6145},{47.327,93.3513},{49.064,95.0881},{50.800,95.5222},{52.537,95.9564},{54.274,96.8248},{56.011,96.3906},{57.748,95.9564},{59.484,95.9564},{61.221,95.0881},{62.958,93.7855},{64.695,93.3513},{66.431,92.4829},{68.168,91.6145},{69.905,91.1803},{71.642,88.5752},{73.378,85.5358},{75.115,82.0623},{76.852,77.7204},{78.589,76.4178},{80.326,73.8126},{82.062,71.2075},{83.799,68.6023},{85.536,64.2604},{87.273,62.5237},{89.009,59.9185},{90.746,54.7082},{92.483,51.2347},{94.220,47.3269},{95.956,45.5902},{97.693,44.2876},{99.430,42.5508},{101.167,41.6824},{102.904,41.6824},{104.640,42.9850},{106.377,44.7218},{108.114,46.0244},{109.851,49.9321},{111.587,54.7082},{113.324,56.8792},{115.061,59.0501},{116.798,60.7869},{118.534,62.9578},{120.271,63.8262},{122.008,66.8656},{123.745,68.6023},{125.481,70.3391},{127.218,72.9443},{128.955,74.6810},{130.692,77.7204},{132.429,78.5888},{134.165,81.6281},{135.902,84.6674},{137.639,85.1016},{139.376,86.8384},{141.112,87.7068},{142.849,88.5752},{144.586,91.1803},{146.323,93.3513},{148.059,95.0881},{149.796,95.0881},{151.533,97.2590},{153.270,97.6932},{155.007,98.1274},{156.743,97.6932},{158.480,97.6932},{160.217,97.2590},{161.954,95.5222},{163.690,94.2197},{165.427,89.8778},{167.164,85.9700},{168.901,85.5358},{170.637,83.7991},{172.374,81.6281},{174.111,78.5888},{175.848,75.5494},{177.585,71.6417},{179.321,66.8656},{181.058,64.2604},{182.795,61.6553},{184.532,57.7475},{186.268,54.7082},{188.005,49.4979},{189.742,43.4192},{191.479,39.5115},{193.215,38.6431},{194.952,39.5115},{196.689,41.6824},{198.426,42.1166},{200.163,45.5902}}
reinwardtii[2]={{0.434,117.666},{2.171,119.837},{3.908,121.140},{5.644,123.745},{7.381,126.784},{9.118,129.823},{10.855,131.560},{12.592,133.297},{14.328,133.731},{16.065,135.902},{17.802,136.336},{19.539,138.073},{21.275,138.507},{23.012,139.810},{24.749,142.415},{26.486,143.718},{28.222,145.454},{29.959,147.625},{31.696,149.796},{33.433,151.533},{35.170,152.836},{36.906,153.704},{38.643,155.441},{40.380,155.875},{42.117,157.612},{43.853,158.914},{45.590,159.348},{47.327,161.519},{49.064,162.822},{50.800,163.256},{52.537,163.690},{54.274,163.690},{56.011,163.256},{57.748,162.388},{59.484,161.085},{61.221,160.651},{62.958,158.480},{64.695,155.441},{66.431,155.007},{68.168,153.270},{69.905,150.665},{71.642,148.928},{73.378,146.323},{75.115,144.152},{76.852,142.415},{78.589,138.507},{80.326,132.429},{82.062,128.521},{83.799,121.574},{83.799,125.916},{85.536,118.969},{87.273,117.232},{89.009,107.680},{89.009,112.890},{89.009,116.363},{90.746,98.127},{90.746,103.772},{92.483,92.049},{92.483,95.088},{94.220,88.141},{95.956,86.404},{97.693,86.404},{99.430,89.009},{101.167,89.878},{102.904,90.746},{104.640,92.483},{106.377,93.785},{108.114,95.088},{109.851,96.825},{111.587,98.996},{113.324,99.430},{115.061,100.733},{116.798,101.167},{118.534,101.601},{120.271,102.469},{122.008,102.904},{123.745,102.904},{125.481,103.338},{127.218,103.772},{128.955,103.772},{130.692,102.904},{132.429,102.469},{134.165,101.601},{135.902,100.733},{137.639,98.562},{139.376,97.259},{141.112,95.522},{142.849,94.220},{144.586,92.917},{146.323,90.746},{148.059,90.312},{149.796,87.273},{151.533,83.365},{153.270,82.496},{155.007,80.326},{156.743,78.589},{158.480,73.378},{160.217,71.642},{161.954,69.905},{163.690,68.602},{165.427,63.826},{167.164,60.353},{168.901,19.973},{168.901,52.537},{168.901,58.182},{170.637,18.670},{170.637,24.315},{170.637,45.156},{172.374,17.368},{172.374,27.788},{172.374,37.775},{174.111,16.499},{175.848,16.065},{177.585,15.631},{179.321,15.197},{181.058,15.197}}
reinwardtii[3]={{0.434,42.9850},{2.171,43.8534},{3.908,48.6295},{5.644,51.6689},{7.381,54.7082},{9.118,57.7475},{10.855,60.7869},{12.592,64.2604},{14.328,68.6023},{16.065,71.2075},{17.802,73.3785},{19.539,76.4178},{21.275,79.4571},{23.012,81.6281},{24.749,83.3649},{26.486,85.1016},{28.222,86.8384},{29.959,88.1410},{31.696,88.1410},{33.433,87.2726},{35.170,87.2726},{36.906,85.9700},{38.643,84.2333},{40.380,82.4965},{42.117,81.1939},{43.853,80.3255},{45.590,75.9836},{47.327,74.2468},{49.064,72.5101},{50.800,66.4314},{52.537,65.5630},{54.274,65.9972},{56.011,66.4314},{57.748,66.4314},{59.484,66.4314},{61.221,63.8262},{62.958,61.6553},{64.695,60.7869},{66.431,58.6159},{68.168,55.5766},{69.905,53.4056},{71.642,51.2347},{73.378,48.6295},{75.115,46.4585},{76.852,46.4585},{78.589,45.5902},{80.326,46.0244},{82.062,47.3269},{83.799,47.3269},{85.536,46.8927},{87.273,46.0244},{89.009,42.5508},{90.746,39.9457},{92.483,39.5115},{94.220,40.8141},{95.956,41.2482},{97.693,42.1166},{99.430,44.2876},{101.167,47.7611},{102.904,51.6689},{104.640,52.9714},{106.377,54.7082},{108.114,57.7475},{109.851,61.2211},{111.587,61.6553},{113.324,64.2604},{115.061,66.4314},{116.798,68.6023},{118.534,69.4707},{120.271,70.7733},{122.008,71.2075},{123.745,73.3785},{125.481,76.8520},{127.218,79.0229},{128.955,80.7597},{130.692,82.0623},{132.429,82.4965},{134.165,84.2333},{135.902,84.6674},{137.639,85.9700},{139.376,87.2726},{141.112,87.7068},{142.849,89.0094},{144.586,87.7068},{146.323,87.2726},{148.059,86.8384},{149.796,85.1016},{151.533,84.2333},{153.270,82.4965},{155.007,79.0229},{156.743,77.2862},{158.480,74.6810},{160.217,72.9443},{161.954,71.2075},{163.690,68.1682},{165.427,62.5237},{167.164,60.3527},{168.901,57.7475},{170.637,54.7082},{172.374,52.5372},{174.111,50.8005},{175.848,49.0637},{177.585,42.5508},{177.585,50.3663},{179.321,39.0773},{179.321,45.5902},{179.321,52.1030},{181.058,37.7747},{181.058,46.8927},{182.795,35.6037},{182.795,38.6431},{184.532,32.9986},{184.532,38.2089},{186.268,13.0258},{186.268,19.1045},{186.268,23.8806},{186.268,29.5251},{188.005,9.5522},{189.742,8.2496},{191.479,8.2496},{193.215,8.2496},{194.952,8.6838},{196.689,11.2890},{198.426,12.1574},{200.163,14.3283}}
reinwardtii[4]={{0.434,11.7232},{2.171,14.7625},{2.171,25.1831},{3.908,19.5386},{3.908,26.9199},{5.644,26.0515},{7.381,26.4857},{9.118,26.9199},{10.855,29.0909},{12.592,30.3934},{14.328,31.2618},{14.328,35.1696},{16.065,38.6431},{17.802,42.9850},{19.539,49.0637},{21.275,51.6689},{23.012,54.2740},{24.749,57.3134},{26.486,60.7869},{28.222,62.0895},{29.959,64.6946},{31.696,68.1682},{33.433,69.9049},{35.170,70.7733},{36.906,72.5101},{38.643,73.8126},{40.380,73.3785},{42.117,74.2468},{43.853,73.3785},{45.590,72.0759},{47.327,71.6417},{49.064,69.0365},{50.800,67.2998},{52.537,66.8656},{54.274,65.5630},{56.011,64.2604},{57.748,61.2211},{59.484,59.4843},{61.221,51.6689},{61.221,56.8792},{62.958,50.8005},{64.695,49.0637},{66.431,47.3269},{68.168,46.4585},{69.905,40.8141},{71.642,39.0773},{73.378,34.3012},{75.115,22.1438},{75.115,23.8806},{75.115,32.1302},{76.852,24.3148},{78.589,24.3148},{80.326,22.5780},{82.062,21.2754},{83.799,19.5386},{85.536,17.8019},{87.273,18.2361},{89.009,21.7096},{90.746,23.8806},{92.483,26.9199},{94.220,28.6567},{95.956,31.2618},{97.693,35.1696},{99.430,36.9063},{101.167,39.9457},{102.904,42.1166},{104.640,43.8534},{106.377,43.8534},{108.114,46.4585},{109.851,49.0637},{111.587,50.3663},{113.324,52.1030},{115.061,53.8398},{116.798,56.0108},{118.534,57.7475},{120.271,59.9185},{122.008,60.3527},{122.008,68.1682},{122.008,71.2075},{123.745,61.2211},{123.745,65.1288},{123.745,72.0759},{125.481,77.7204},{127.218,80.3255},{128.955,81.6281},{130.692,73.8126},{130.692,79.4571},{132.429,72.0759},{134.165,70.7733},{135.902,70.7733},{137.639,69.9049},{139.376,69.0365},{141.112,68.6023},{142.849,65.9972},{144.586,62.9578},{146.323,59.9185},{148.059,59.0501},{149.796,53.8398},{149.796,56.8792},{151.533,52.5372},{153.270,45.1560},{153.270,50.3663},{155.007,43.8534},{156.743,43.4192},{158.480,39.5115},{160.217,37.7747},{161.954,33.4328},{163.690,31.2618},{165.427,31.2618},{167.164,26.9199},{168.901,23.4464},{170.637,18.6703},{172.374,4.3419},{172.374,10.8548},{172.374,15.6309},{174.111,2.1710},{175.848,0.4342},{177.585,0.8684},{179.321,2.6052},{181.058,4.3419},{182.795,4.7761},{184.532,5.2103},{186.268,6.5129},{188.005,10.4206},{189.742,11.2890}}

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