(*******************************  macrodonta  *)

Needs["Splines`"]

macrodonta[1]={{0.312,39.2516},{1.558,37.0709},{2.804,35.2018},{4.050,35.2018},{5.296,36.4479},{6.542,38.9401},{7.788,40.4977},{9.034,41.7437},{10.280,42.6783},{11.526,43.6129},{12.772,43.9244},{14.018,44.5474},{15.265,45.4820},{16.511,46.7281},{17.757,47.3511},{19.003,47.9741},{20.249,49.2202},{21.495,50.4663},{22.741,50.7778},{23.987,51.7124},{25.233,52.3354},{26.479,52.9585},{27.725,54.2046},{28.971,55.1391},{30.217,55.7622},{31.464,56.6967},{32.710,57.3198},{33.956,57.9428},{35.202,58.5658},{36.448,59.1889},{37.694,59.5004},{38.940,60.4350},{40.186,61.6810},{41.432,62.6156},{42.678,62.9271},{43.924,64.1732},{45.170,64.7962},{46.417,66.6654},{47.663,67.2884},{48.909,68.2230},{50.155,68.8460},{51.401,68.8460},{52.647,68.8460},{53.893,69.1575},{55.139,69.4691},{56.385,69.4691},{57.631,69.4691},{58.877,70.4036},{60.123,70.7151},{61.370,70.7151},{62.616,70.7151},{63.862,70.7151},{65.108,71.3382},{66.354,71.0267},{67.600,70.7151},{68.846,70.7151},{70.092,70.7151},{71.338,70.7151},{72.584,71.0267},{73.830,70.7151},{75.076,70.0921},{76.323,69.4691},{77.569,69.1575},{78.815,68.8460},{80.061,68.8460},{81.307,68.5345},{82.553,67.9115},{83.799,67.2884},{85.045,66.0423},{86.291,65.4193},{87.537,64.7962},{88.783,63.5502},{90.029,61.9926},{91.275,60.4350},{92.522,59.1889},{93.768,57.9428},{95.014,56.6967},{96.260,55.1391},{97.506,53.2700},{98.752,52.3354},{99.998,50.4663},{101.244,49.5317},{102.490,49.5317},{103.736,49.5317},{104.982,48.9087},{106.228,49.2202},{107.475,49.8433},{108.721,50.4663},{109.967,51.7124},{111.213,52.3354},{112.459,52.9585},{113.705,53.5815},{114.951,55.1391},{116.197,56.3852},{117.443,56.6967},{118.689,57.0082},{119.935,57.6313},{121.181,59.1889},{122.428,60.4350},{123.674,61.0580},{124.920,61.9926},{126.166,62.9271},{127.412,63.2386},{128.658,64.1732},{129.904,65.4193},{131.150,66.3539},{132.396,66.9769},{133.642,67.5999},{134.888,67.5999},{136.134,68.5345},{137.381,69.4691},{138.627,71.0267},{139.873,71.3382},{141.119,71.3382},{142.365,71.9612},{143.611,72.5843},{144.857,72.5843},{146.103,72.5843},{147.349,72.2727},{148.595,71.9612},{149.841,71.9612},{151.087,71.9612},{152.333,71.9612},{153.580,71.9612},{154.826,71.9612},{156.072,71.9612},{157.318,71.9612},{158.564,71.9612},{159.810,71.9612},{161.056,71.6497},{162.302,71.3382},{163.548,70.7151},{164.794,70.4036},{166.040,69.7806},{167.286,68.8460},{168.533,68.5345},{169.779,67.9115},{171.025,66.9769},{172.271,66.3539},{173.517,65.4193},{174.763,64.1732},{176.009,63.5502},{177.255,62.6156},{178.501,61.3695},{179.747,59.1889},{180.993,57.9428},{182.239,56.6967},{183.486,54.8276},{184.732,52.9585},{185.978,50.7778},{187.224,50.1548},{188.470,50.1548},{189.716,49.8433},{190.962,49.2202},{192.208,47.9741},{193.454,47.6626},{194.700,47.0396},{195.946,46.7281},{197.192,46.1050},{198.439,44.8589},{199.685,43.9244},{200.931,42.6783},{202.177,41.1207},{203.423,40.4977},{204.669,39.5631},{205.915,37.6940},{207.161,36.7594},{208.407,36.7594},{209.653,37.0709},{210.899,38.0055},{212.145,38.9401}}
macrodonta[2]={{0.312,17.1336},{1.558,17.1336},{2.804,16.8221},{4.050,16.5106},{5.296,15.8875},{6.542,16.1991},{7.788,16.1991},{9.034,15.8875},{10.280,15.5760},{11.526,15.5760},{12.772,15.8875},{14.018,16.8221},{15.265,17.4451},{16.511,18.3797},{17.757,19.0027},{19.003,20.2488},{20.249,21.8064},{21.495,22.4295},{22.741,23.6756},{23.987,23.9871},{25.233,24.2986},{26.479,25.8562},{27.725,27.4138},{28.971,28.0368},{30.217,28.6599},{31.464,30.2175},{32.710,30.8405},{33.956,31.7751},{35.202,33.3327},{36.448,33.6442},{37.694,34.5788},{38.940,35.5133},{40.186,36.7594},{41.432,36.7594},{42.678,37.0709},{43.924,37.6940},{45.170,38.3170},{46.417,39.5631},{47.663,40.8092},{48.909,41.1207},{50.155,41.4322},{51.401,42.0553},{52.647,43.6129},{53.893,44.2359},{55.139,44.5474},{56.385,43.9244},{57.631,43.9244},{58.877,44.8589},{60.123,45.7935},{61.370,45.7935},{62.616,45.7935},{63.862,46.4165},{65.108,47.0396},{66.354,47.9741},{67.600,48.2857},{68.846,48.9087},{70.092,49.8433},{71.338,50.4663},{72.584,50.4663},{73.830,50.1548},{75.076,50.7778},{76.323,50.7778},{77.569,50.7778},{78.815,50.1548},{80.061,50.1548},{81.307,50.4663},{82.553,50.7778},{83.799,50.7778},{85.045,51.0894},{86.291,51.0894},{87.537,51.4009},{88.783,51.7124},{90.029,52.0239},{91.275,52.0239},{92.522,51.7124},{93.768,51.4009},{95.014,51.4009},{96.260,52.0239},{97.506,51.7124},{98.752,50.7778},{99.998,50.4663},{101.244,50.1548},{102.490,49.8433},{103.736,48.9087},{104.982,48.2857},{106.228,48.9087},{107.475,48.9087},{108.721,48.5972},{109.967,47.0396},{111.213,47.0396},{112.459,46.7281},{113.705,45.4820},{114.951,44.5474},{116.197,43.9244},{117.443,43.9244},{118.689,42.9898},{119.935,41.7437},{121.181,41.4322},{122.428,40.8092},{123.674,40.1861},{124.920,39.5631},{126.166,39.2516},{127.412,38.6285},{128.658,38.3170},{129.904,37.6940},{131.150,37.6940},{132.396,37.0709},{133.642,36.4479},{134.888,36.4479},{136.134,36.7594},{137.381,37.0709},{138.627,37.3825},{139.873,38.0055},{141.119,38.9401},{142.365,39.8746},{143.611,40.1861},{144.857,40.1861},{146.103,40.1861},{147.349,41.1207},{148.595,42.0553},{149.841,43.3013},{151.087,44.5474},{152.333,45.4820},{153.580,46.1050},{154.826,47.0396},{156.072,47.9741},{157.318,48.5972},{158.564,48.9087},{159.810,48.9087},{161.056,49.5317},{162.302,50.7778},{163.548,51.0894},{164.794,51.0894},{166.040,52.3354},{167.286,52.9585},{168.533,53.2700},{169.779,53.8930},{171.025,53.8930},{172.271,54.2046},{173.517,54.8276},{174.763,55.7622},{176.009,56.0737},{177.255,56.3852},{178.501,56.3852},{179.747,56.3852},{180.993,56.6967},{182.239,57.0082},{183.486,57.0082},{184.732,57.0082},{185.978,56.6967},{187.224,57.0082},{188.470,57.0082},{189.716,57.9428},{190.962,58.2543},{192.208,57.9428},{193.454,57.6313},{194.700,58.2543},{195.946,59.1889},{197.192,59.5004},{198.439,59.1889},{199.685,58.8774},{200.931,58.5658},{202.177,58.2543},{203.423,58.5658},{204.669,58.2543},{205.915,57.3198},{207.161,57.0082},{208.407,56.3852},{209.653,56.3852},{210.899,57.0082},{212.145,56.3852},{213.391,55.7622},{214.638,55.4506},{215.884,54.2046},{217.130,53.5815},{218.376,53.2700},{219.622,53.2700},{220.868,52.6470},{222.114,52.6470},{223.360,52.0239},{224.606,51.0894},{225.852,50.4663},{227.098,49.8433},{228.344,49.2202},{229.591,48.5972},{230.837,48.2857},{232.083,47.9741},{233.329,47.0396},{234.575,46.1050},{235.821,45.4820},{237.067,45.1705},{238.313,44.8589},{239.559,44.2359},{240.805,43.6129},{242.051,42.9898},{243.297,42.0553},{244.544,41.1207},{245.790,40.8092},{247.036,40.8092},{248.282,39.8746},{249.528,38.9401},{250.774,38.3170},{252.020,38.3170},{253.266,38.3170},{254.512,38.9401},{255.758,39.2516},{257.004,40.1861},{258.250,40.1861},{259.497,40.1861},{260.743,40.8092},{261.989,41.1207},{263.235,42.0553},{264.481,42.0553}}
macrodonta[3]={{0.312,8.4111},{1.558,8.4111},{2.804,9.0341},{4.050,9.3456},{5.296,9.6571},{6.542,11.5263},{7.788,12.4608},{9.034,13.0839},{10.280,13.7069},{11.526,14.6415},{12.772,15.8875},{14.018,17.4451},{15.265,18.3797},{16.511,19.0027},{17.757,19.6258},{19.003,20.2488},{20.249,21.1834},{21.495,22.7410},{22.741,22.1180},{23.987,23.0525},{23.987,24.9216},{25.233,24.6101},{26.479,23.3640},{27.725,24.2986},{28.971,25.2332},{30.217,25.8562},{31.464,26.1677},{32.710,26.7908},{33.956,27.4138},{35.202,27.7253},{36.448,27.7253},{37.694,27.7253},{38.940,28.0368},{40.186,28.3484},{41.432,28.9714},{42.678,28.9714},{43.924,28.9714},{45.170,28.9714},{46.417,28.9714},{47.663,28.9714},{48.909,28.9714},{50.155,28.9714},{51.401,28.9714},{52.647,28.9714},{53.893,28.9714},{55.139,29.2829},{56.385,29.2829},{57.631,28.3484},{58.877,28.3484},{60.123,28.3484},{61.370,28.3484},{62.616,28.0368},{63.862,27.4138},{65.108,27.7253},{66.354,28.0368},{67.600,27.4138},{68.846,26.7908},{70.092,26.4792},{71.338,27.7253},{72.584,26.7908},{72.584,28.9714},{73.830,25.5447},{73.830,27.7253},{75.076,24.6101},{76.323,24.9216},{77.569,24.6101},{78.815,24.6101},{80.061,24.2986},{81.307,23.3640},{82.553,23.0525},{83.799,22.7410},{85.045,22.4295},{86.291,22.1180},{87.537,22.1180},{88.783,22.1180},{90.029,22.1180},{91.275,22.4295},{92.522,23.0525},{93.768,23.6756},{95.014,24.6101},{96.260,25.2332},{97.506,25.8562},{98.752,27.1023},{99.998,28.0368},{101.244,27.4138},{102.490,28.9714},{103.736,29.5944},{104.982,30.5290},{106.228,30.8405},{107.475,30.8405},{108.721,31.7751},{109.967,32.0866},{111.213,32.7096},{112.459,33.6442},{113.705,34.2672},{114.951,34.5788},{116.197,34.8903},{117.443,35.2018},{118.689,35.2018},{119.935,35.5133},{121.181,35.8248},{122.428,36.1364},{123.674,36.4479},{124.920,36.4479},{126.166,36.4479},{127.412,35.8248},{128.658,36.7594},{129.904,37.0709},{131.150,36.7594},{132.396,37.0709},{133.642,37.0709},{134.888,37.0709},{136.134,36.4479},{137.381,36.1364},{138.627,36.7594},{139.873,37.3825},{141.119,36.7594},{142.365,36.1364},{143.611,35.8248},{144.857,35.8248},{146.103,35.8248},{147.349,35.5133},{148.595,34.8903},{149.841,34.5788},{151.087,34.5788},{152.333,34.8903},{153.580,34.2672},{154.826,33.9557},{156.072,33.3327},{157.318,33.0212},{158.564,32.7096},{159.810,32.7096},{161.056,32.3981},{162.302,32.0866},{163.548,32.0866},{164.794,32.0866},{166.040,32.0866},{167.286,30.8405},{168.533,29.9060},{169.779,29.5944},{171.025,29.2829},{172.271,29.2829},{173.517,28.9714},{174.763,28.6599},{176.009,27.4138},{177.255,26.4792},{178.501,26.4792},{179.747,26.4792},{180.993,25.2332},{182.239,24.2986},{183.486,23.9871},{184.732,23.9871},{185.978,22.4295},{187.224,21.4949},{188.470,21.1834},{189.716,20.5603},{190.962,20.5603},{192.208,21.4949},{193.454,21.4949},{194.700,22.1180},{195.946,22.4295},{197.192,22.4295},{198.439,22.7410}}
macrodonta[4]={{0.312,7.7880},{1.558,7.4765},{2.804,7.1650},{4.050,7.1650},{5.296,7.1650},{6.542,7.7880},{7.788,6.8534},{9.034,6.5419},{10.280,6.8534},{11.526,6.5419},{12.772,6.5419},{14.018,8.0995},{15.265,9.3456},{16.511,10.9032},{17.757,11.2147},{19.003,11.8378},{20.249,12.7723},{21.495,14.0184},{22.741,15.8875},{23.987,16.8221},{25.233,18.6912},{26.479,19.3143},{27.725,24.9216},{28.971,25.8562},{30.217,27.1023},{31.464,26.4792},{32.710,26.7908},{33.956,27.7253},{35.202,26.7908},{36.448,27.1023},{37.694,28.0368},{38.940,28.6599},{40.186,28.9714},{41.432,30.2175},{42.678,31.1520},{43.924,31.4636},{45.170,31.4636},{46.417,32.3981},{47.663,33.3327},{48.909,33.3327},{50.155,33.9557},{51.401,34.2672},{52.647,34.5788},{53.893,34.8903},{55.139,35.5133},{56.385,35.8248},{57.631,36.4479},{58.877,36.4479},{60.123,37.6940},{61.370,37.6940},{62.616,37.6940},{63.862,37.6940},{65.108,38.9401},{66.354,38.9401},{67.600,38.9401},{68.846,38.9401},{70.092,39.5631},{71.338,40.1861},{72.584,40.4977},{73.830,40.1861},{75.076,40.8092},{76.323,41.4322},{77.569,42.0553},{78.815,41.4322},{80.061,41.4322},{81.307,41.4322},{82.553,41.1207},{83.799,40.8092},{85.045,41.4322},{86.291,41.4322},{87.537,41.4322},{88.783,40.8092},{90.029,40.8092},{91.275,40.8092},{92.522,40.8092},{93.768,40.8092},{95.014,40.8092},{96.260,40.8092},{97.506,40.8092},{98.752,40.1861},{99.998,40.1861},{101.244,40.8092},{102.490,40.8092},{103.736,40.1861},{104.982,39.5631},{106.228,39.2516},{107.475,38.9401},{108.721,38.6285},{109.967,38.0055},{111.213,38.0055},{112.459,37.3825},{113.705,36.4479},{114.951,36.4479},{116.197,37.0709},{117.443,36.7594},{118.689,36.1364},{119.935,35.8248},{121.181,36.7594},{122.428,35.2018},{123.674,33.9557},{124.920,33.9557},{126.166,33.9557},{127.412,33.9557},{128.658,33.9557},{129.904,32.7096},{131.150,32.0866},{132.396,31.4636},{133.642,31.4636},{134.888,30.8405},{136.134,30.8405},{137.381,30.8405},{138.627,31.4636},{139.873,31.7751},{141.119,32.0866},{142.365,32.0866},{143.611,32.3981},{144.857,32.7096},{146.103,33.3327},{147.349,33.9557},{148.595,34.2672},{149.841,34.8903},{151.087,36.1364},{152.333,36.1364},{153.580,36.1364},{154.826,38.0055},{156.072,38.6285},{157.318,39.2516},{158.564,40.8092},{159.810,40.8092},{161.056,40.8092},{162.302,40.8092},{163.548,40.8092},{164.794,41.4322},{166.040,40.8092},{167.286,41.4322},{168.533,41.4322},{169.779,42.9898},{171.025,42.6783},{172.271,42.6783},{173.517,41.7437},{174.763,41.4322},{176.009,41.4322},{177.255,41.1207},{178.501,40.8092},{179.747,40.8092},{180.993,40.4977},{182.239,38.9401},{183.486,38.9401},{184.732,38.9401},{185.978,38.3170},{187.224,37.3825},{188.470,36.4479},{189.716,35.8248},{190.962,35.5133},{192.208,33.9557},{193.454,34.2672},{194.700,34.5788},{195.946,34.5788},{197.192,34.2672},{198.439,32.0866},{199.685,28.9714},{200.931,28.3484},{202.177,27.1023},{203.423,27.1023},{204.669,26.4792},{205.915,25.5447},{207.161,24.9216},{208.407,24.9216},{209.653,25.2332},{210.899,25.2332},{212.145,25.2332},{213.391,25.2332},{214.638,25.8562},{215.884,26.4792},{217.130,26.7908},{218.376,27.1023},{219.622,27.7253}}

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