(*******************************  saxatilis  *)

Needs["Splines`"]

saxatilis[1]={{0.641,17.3077},{3.205,16.0256},{5.769,16.0256},{8.333,16.0256},{10.897,17.9487},{13.462,19.2308},{16.026,19.8718},{18.590,23.0769},{21.154,24.3590},{23.718,26.9231},{26.282,29.4872},{28.846,31.4103},{31.410,34.6154},{33.974,40.3846},{36.538,44.8718},{39.103,48.0769},{41.667,50.0000},{44.231,51.9231},{46.795,53.8462},{49.359,54.4872},{51.923,55.7692},{54.487,56.4103},{57.051,57.0513},{59.615,57.0513},{62.179,57.0513},{64.744,57.0513},{67.308,57.0513},{69.872,56.4103},{72.436,55.7692},{75.000,55.1282},{77.564,53.8462},{80.128,51.9231},{82.692,50.0000},{85.256,47.4359},{87.821,45.5128},{90.385,42.9487},{92.949,42.3077},{95.513,40.3846},{98.077,39.1026},{100.641,38.4615},{103.205,36.5385},{105.769,36.5385},{108.333,37.8205},{110.897,36.5385},{113.462,36.5385},{116.026,36.5385},{118.590,36.5385},{121.154,37.8205},{123.718,38.4615},{126.282,39.1026},{128.846,41.0256},{131.410,42.9487},{133.974,46.7949},{136.538,50.6410},{139.103,53.2051},{141.667,55.1282},{144.231,58.3333},{146.795,58.9744},{149.359,58.9744},{151.923,59.6154},{154.487,60.2564},{157.051,59.6154},{159.615,59.6154},{162.179,59.6154},{164.744,59.6154},{167.308,59.6154},{169.872,59.6154},{172.436,58.9744},{175.000,58.3333},{177.564,57.6923},{180.128,57.0513},{182.692,55.7692},{185.256,53.8462},{187.821,53.2051},{190.385,51.9231},{192.949,50.0000},{195.513,48.7179},{198.077,46.7949},{200.641,44.8718},{203.205,42.9487},{205.769,41.6667},{208.333,40.3846},{210.897,39.7436},{213.462,37.1795},{216.026,35.8974},{218.590,33.9744},{221.154,32.0513},{223.718,32.6923},{226.282,33.3333},{228.846,35.2564},{231.410,37.1795}}
saxatilis[2]={{0.641,10.8974},{3.205,10.8974},{5.769,12.8205},{8.333,16.6667},{10.897,19.2308},{13.462,21.7949},{16.026,25.0000},{18.590,26.9231},{21.154,29.4872},{23.718,32.0513},{26.282,34.6154},{28.846,35.2564},{31.410,37.1795},{33.974,38.4615},{36.538,39.1026},{39.103,39.1026},{41.667,39.7436},{44.231,40.3846},{46.795,41.6667},{49.359,40.3846},{51.923,39.7436},{54.487,39.1026},{57.051,38.4615},{59.615,37.8205},{62.179,37.1795},{64.744,35.2564},{67.308,32.0513},{69.872,29.4872},{72.436,27.5641},{75.000,26.2821},{77.564,25.0000},{80.128,25.0000},{82.692,23.7179},{85.256,24.3590},{87.821,25.6410},{90.385,26.2821},{92.949,26.9231},{95.513,27.5641},{98.077,28.8462},{100.641,30.1282},{103.205,31.4103},{105.769,33.3333},{108.333,33.9744},{110.897,35.2564},{113.462,36.5385},{116.026,38.4615},{118.590,40.3846},{121.154,40.3846},{123.718,40.3846},{126.282,41.0256},{128.846,41.6667},{131.410,41.6667},{133.974,41.6667},{136.538,41.6667},{139.103,41.6667},{141.667,41.6667},{144.231,41.0256},{146.795,40.3846},{149.359,40.3846},{151.923,39.7436},{154.487,39.1026},{157.051,37.8205},{159.615,35.8974},{162.179,33.3333},{164.744,31.4103},{167.308,29.4872},{169.872,26.9231},{172.436,23.7179},{175.000,19.2308},{177.564,16.6667},{180.128,12.8205},{182.692,10.8974},{185.256,9.6154},{187.821,9.6154},{190.385,10.8974},{192.949,10.8974},{195.513,12.1795}}
saxatilis[3]={{5.769,1.2821},{5.769,5.1282},{8.333,8.3333},{10.897,11.5385},{13.462,14.1026},{16.026,15.3846},{18.590,17.9487},{21.154,20.5128},{23.718,21.7949},{26.282,23.0769},{28.846,25.0000},{31.410,26.2821},{33.974,28.2051},{36.538,28.8462},{39.103,30.1282},{41.667,32.0513},{44.231,33.3333},{46.795,33.9744},{49.359,33.9744},{51.923,32.6923},{54.487,32.6923},{57.051,32.6923},{59.615,33.9744},{62.179,33.9744},{64.744,33.3333},{67.308,32.0513},{69.872,31.4103},{72.436,29.4872},{75.000,28.8462},{77.564,26.9231},{80.128,25.0000},{82.692,22.4359},{85.256,20.5128},{87.821,19.8718},{90.385,18.5897},{92.949,18.5897},{95.513,18.5897},{98.077,20.5128},{100.641,23.0769},{103.205,28.2051},{105.769,31.4103},{108.333,33.3333},{110.897,35.2564},{113.462,35.8974},{116.026,37.1795},{118.590,38.4615},{121.154,39.7436},{123.718,41.0256},{126.282,41.6667},{128.846,42.3077},{131.410,42.9487},{133.974,42.9487},{136.538,43.5897},{139.103,44.2308},{141.667,44.2308},{144.231,44.2308},{146.795,43.5897},{149.359,42.9487},{151.923,42.3077},{154.487,41.0256},{157.051,40.3846},{159.615,40.3846},{162.179,39.7436},{164.744,39.1026},{167.308,39.1026},{169.872,39.1026},{172.436,39.1026},{175.000,39.1026},{177.564,37.8205},{180.128,34.6154},{182.692,32.6923},{185.256,32.6923},{187.821,30.7692},{190.385,28.2051},{192.949,25.6410},{195.513,22.4359},{198.077,19.2308},{200.641,17.3077},{203.205,16.0256},{205.769,16.0256},{208.333,16.6667}}
saxatilis[4]={{0.641,17.9487},{3.205,17.3077},{5.769,17.3077},{8.333,17.9487},{10.897,21.7949},{13.462,25.6410},{16.026,28.2051},{18.590,30.7692},{21.154,33.3333},{23.718,37.1795},{26.282,39.7436},{28.846,42.9487},{31.410,44.8718},{33.974,46.7949},{36.538,48.0769},{39.103,49.3590},{41.667,49.3590},{44.231,49.3590},{46.795,49.3590},{49.359,49.3590},{51.923,49.3590},{54.487,49.3590},{57.051,48.0769},{59.615,46.7949},{62.179,45.5128},{64.744,44.8718},{67.308,43.5897},{69.872,41.0256},{72.436,39.7436},{75.000,35.8974},{77.564,32.6923},{80.128,27.5641},{82.692,26.2821},{85.256,26.9231},{87.821,27.5641},{90.385,27.5641},{92.949,27.5641},{95.513,27.5641},{98.077,31.4103},{100.641,35.8974},{103.205,38.4615},{105.769,39.7436},{108.333,41.6667},{110.897,43.5897},{113.462,44.2308},{116.026,44.2308},{118.590,45.5128},{121.154,45.5128},{123.718,45.5128},{126.282,47.4359},{128.846,48.0769},{131.410,48.0769},{133.974,48.0769},{136.538,48.0769},{139.103,48.0769},{141.667,48.0769},{144.231,48.0769},{146.795,48.0769},{149.359,47.4359},{151.923,46.7949},{154.487,45.5128},{157.051,44.2308},{159.615,42.9487},{162.179,41.0256},{164.744,38.4615},{167.308,35.8974},{169.872,33.3333},{172.436,30.7692},{175.000,27.5641},{177.564,24.3590},{180.128,25.0000},{182.692,26.2821}}

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