(*******************************  haradjiannii  *)

Needs["Splines`"]

haradjiannii[1]={{0.389,19.8186},{1.943,19.4300},{3.497,19.0414},{5.052,18.2642},{6.606,18.6528},{8.161,19.0414},{9.715,17.8756},{11.269,17.4870},{12.824,22.1502},{14.378,23.3160},{15.933,27.2020},{17.487,28.7564},{19.041,30.3108},{20.596,33.0310},{22.150,36.1398},{23.705,38.4714},{25.259,39.6372},{26.813,41.1916},{28.368,42.3574},{29.922,43.1346},{31.477,44.3004},{33.031,44.6890},{34.585,45.4662},{36.140,46.2434},{37.694,47.0206},{39.249,47.0206},{40.803,47.7978},{42.357,47.7978},{43.912,48.1864},{45.466,48.5750},{47.021,48.5750},{48.575,48.5750},{50.129,48.5750},{51.684,47.7978},{53.238,47.4092},{54.793,47.0206},{56.347,46.2434},{57.901,46.2434},{59.456,45.8548},{61.010,45.4662},{62.565,44.6890},{64.119,43.5232},{65.673,42.7460},{67.228,41.9688},{68.782,41.1916},{70.337,40.0258},{71.891,39.2486},{73.445,37.6942},{75.000,36.5284},{76.554,35.3626},{78.109,34.1968},{79.663,33.4196},{81.217,33.0310},{82.772,32.2538},{84.326,31.4766},{85.881,31.4766},{87.435,32.6424},{88.989,33.8082},{90.544,34.1968},{92.098,36.9170},{93.653,38.0828},{95.207,37.6942},{96.761,36.9170},{98.316,37.6942},{99.870,37.6942},{101.425,38.8600},{102.979,40.0258},{104.533,41.5802},{106.088,41.5802},{107.642,41.5802},{109.197,41.5802},{110.751,42.7460},{112.305,44.3004},{113.860,44.6890},{115.414,45.0776},{116.969,45.4662},{118.523,46.2434},{120.077,46.2434},{121.632,47.0206},{123.186,47.0206},{124.741,47.4092},{126.295,47.7978},{127.849,48.1864},{129.404,49.3522},{130.958,50.1294},{132.513,49.3522},{134.067,49.3522},{135.621,48.9636},{137.176,49.3522},{138.730,49.3522},{140.285,50.1294},{141.839,50.1294},{143.393,49.3522},{144.948,48.9636},{146.502,48.5750},{148.057,49.3522},{149.611,48.5750},{151.165,48.5750},{152.720,47.7978},{154.274,47.4092},{155.828,47.0206},{157.383,47.0206},{158.937,46.2434},{160.492,45.4662},{162.046,45.0776},{163.600,44.3004},{165.155,42.7460},{166.709,41.1916},{168.264,40.0258},{169.818,38.8600},{171.372,37.3056},{172.927,35.3626},{174.481,33.4196},{176.036,31.8652},{177.590,30.3108},{179.144,29.1450},{180.699,28.3678},{182.253,27.9792},{183.808,27.5906},{185.362,27.5906},{186.916,27.5906},{188.471,27.5906},{190.025,27.2020},{191.580,27.9792},{193.134,28.3678},{194.688,28.3678}}
haradjiannii[2]={{0.389,7.7720},{1.943,7.3834},{3.497,7.3834},{5.052,7.3834},{6.606,8.5492},{8.161,10.4922},{9.715,10.4922},{11.269,10.8808},{12.824,11.2694},{14.378,12.0466},{15.933,13.2124},{17.487,13.6010},{19.041,14.3782},{20.596,14.7668},{22.150,15.9326},{23.705,16.7098},{25.259,17.0984},{26.813,17.4870},{28.368,18.2642},{29.922,19.0414},{31.477,19.4300},{33.031,20.5958},{34.585,20.9844},{36.140,21.3730},{37.694,21.3730},{39.249,19.8186},{40.803,18.6528},{42.357,18.2642},{43.912,17.8756},{45.466,17.4870},{47.021,18.2642},{48.575,17.8756},{50.129,17.4870},{51.684,16.3212},{53.238,15.5440},{54.793,15.1554},{56.347,14.3782},{57.901,13.6010},{59.456,13.2124},{61.010,12.4352},{62.565,11.2694},{64.119,10.8808},{65.673,10.4922},{67.228,10.4922},{68.782,11.2694},{70.337,12.4352},{71.891,13.9896},{73.445,14.7668},{75.000,16.3212},{76.554,17.4870},{78.109,18.2642},{79.663,18.6528},{81.217,19.8186},{82.772,20.2072},{84.326,20.5958},{85.881,21.7616},{87.435,22.9274},{88.989,22.9274},{90.544,22.1502},{92.098,21.7616},{93.653,21.3730},{95.207,21.3730},{96.761,20.5958},{98.316,20.5958},{99.870,20.2072},{101.425,19.8186},{102.979,19.4300},{104.533,19.0414},{106.088,18.2642},{107.642,17.4870},{109.197,16.7098},{110.751,16.3212},{112.305,15.9326},{113.860,15.1554},{115.414,13.9896},{116.969,12.4352},{118.523,11.6580},{120.077,10.8808},{121.632,10.4922},{123.186,9.7150},{124.741,9.3264},{126.295,9.7150},{127.849,10.4922},{129.404,11.6580},{130.958,12.4352},{132.513,13.2124}}
haradjiannii[3]={{0.389,14.7668},{1.943,14.3782},{3.497,14.3782},{5.052,14.3782},{6.606,15.1554},{8.161,15.9326},{9.715,16.7098},{11.269,17.4870},{12.824,18.2642},{14.378,19.4300},{15.933,21.7616},{17.487,23.3160},{19.041,24.4818},{20.596,25.2590},{22.150,26.4248},{23.705,27.5906},{25.259,27.9792},{26.813,28.3678},{28.368,28.7564},{29.922,29.5336},{31.477,29.9222},{33.031,31.0880},{34.585,31.8652},{36.140,32.2538},{37.694,31.4766},{39.249,30.6994},{40.803,30.3108},{42.357,30.3108},{43.912,31.0880},{45.466,31.0880},{47.021,30.3108},{48.575,29.9222},{50.129,29.5336},{51.684,29.1450},{53.238,28.3678},{54.793,27.5906},{56.347,27.2020},{57.901,26.8134},{59.456,25.6476},{61.010,24.8704},{62.565,24.0932},{64.119,23.7046},{65.673,22.9274},{67.228,22.1502},{68.782,21.3730},{70.337,20.5958},{71.891,20.2072},{73.445,19.8186},{75.000,19.0414},{76.554,19.4300},{78.109,20.2072},{79.663,20.5958},{81.217,21.7616},{82.772,22.5388},{84.326,23.3160},{85.881,24.0932},{87.435,24.4818},{88.989,25.2590},{90.544,25.6476},{92.098,26.0362},{93.653,26.8134},{95.207,26.8134},{96.761,27.5906},{98.316,28.3678},{99.870,28.3678},{101.425,29.1450},{102.979,29.1450},{104.533,29.1450},{106.088,29.5336},{107.642,29.1450},{109.197,28.3678},{110.751,27.5906},{112.305,27.5906},{113.860,26.8134},{115.414,26.0362},{116.969,25.6476},{118.523,25.2590},{120.077,24.0932},{121.632,23.3160},{123.186,21.7616},{124.741,20.9844},{126.295,19.0414},{127.849,16.3212},{129.404,15.5440},{130.958,14.7668},{132.513,15.1554},{134.067,15.5440},{135.621,16.3212},{137.176,17.0984},{138.730,17.8756},{140.285,18.6528},{141.839,19.4300},{143.393,19.8186}}
haradjiannii[4]={{0.389,3.8860},{0.389,18.2642},{1.943,3.1088},{1.943,19.0414},{3.497,1.9430},{3.497,19.4300},{5.052,0.7772},{5.052,20.2072},{6.606,0.3886},{6.606,20.9844},{8.161,22.5388},{9.715,24.8704},{11.269,26.4248},{12.824,28.3678},{14.378,29.5336},{15.933,30.3108},{17.487,31.4766},{19.041,32.2538},{20.596,33.4196},{22.150,34.5854},{23.705,34.5854},{25.259,35.7512},{26.813,36.1398},{28.368,36.5284},{29.922,36.5284},{31.477,36.1398},{33.031,36.1398},{34.585,36.1398},{36.140,36.9170},{37.694,36.5284},{39.249,35.7512},{40.803,35.3626},{42.357,35.3626},{43.912,35.3626},{45.466,34.1968},{47.021,33.4196},{48.575,32.2538},{50.129,31.0880},{51.684,30.3108},{53.238,27.5906},{54.793,24.8704},{56.347,23.3160},{57.901,22.1502},{59.456,20.5958},{61.010,17.8756},{62.565,16.3212},{64.119,15.5440},{65.673,15.1554},{67.228,15.5440},{68.782,16.3212},{70.337,17.4870},{71.891,18.2642},{73.445,19.4300},{75.000,20.9844},{76.554,21.7616},{78.109,23.3160},{79.663,24.8704},{81.217,25.2590},{82.772,26.4248},{84.326,27.2020},{85.881,27.5906},{87.435,28.7564},{88.989,29.1450},{90.544,29.5336},{92.098,29.9222},{93.653,31.0880},{95.207,31.8652},{96.761,32.2538},{98.316,33.0310},{99.870,34.9740},{101.425,35.3626},{102.979,34.1968},{104.533,33.0310},{106.088,32.2538},{107.642,31.8652},{109.197,31.4766},{110.751,31.8652},{112.305,31.0880},{113.860,30.6994},{115.414,29.9222},{116.969,27.9792},{118.523,27.2020},{120.077,26.0362},{121.632,23.7046},{123.186,20.9844},{124.741,17.0984},{126.295,14.7668},{127.849,11.6580},{129.404,10.8808},{130.958,10.4922},{132.513,10.4922},{134.067,10.8808},{135.621,11.6580},{137.176,12.8238},{138.730,12.8238}}

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