(*******************************  conica  *)

Needs["Splines`"]

conica[1]={{0.565,4.5195},{2.825,5.6494},{5.084,6.7792},{7.344,7.3442},{9.604,6.2143},{11.864,6.2143},{14.123,7.3442},{16.383,10.7338},{18.643,16.9481},{20.903,23.1624},{23.162,27.6818},{25.422,31.6364},{27.682,35.0260},{29.942,36.7208},{32.201,38.4156},{34.461,40.1104},{36.721,41.2403},{38.981,41.2403},{41.240,41.2403},{43.500,40.6754},{45.760,40.1104},{48.020,39.5455},{50.279,38.4156},{52.539,36.7208},{54.799,34.4611},{57.059,32.7663},{59.318,31.0715},{61.578,28.8117},{63.838,27.6818},{66.097,26.5520},{68.357,25.9870},{70.617,25.4221},{72.877,24.2922},{75.136,24.2922},{77.396,23.7273},{79.656,23.1624},{81.916,23.1624},{84.175,23.1624},{86.435,23.1624},{88.695,23.1624},{90.955,23.1624},{93.214,23.1624},{95.474,23.7273},{97.734,24.8572},{99.994,28.2468},{102.253,31.6364},{104.513,35.0260},{106.773,38.4156},{109.033,39.5455},{111.292,42.9351},{113.552,44.0650},{115.812,45.1949},{118.072,46.3247},{120.331,46.8897},{122.591,46.8897},{124.851,46.8897},{127.111,46.8897},{129.370,46.3247},{131.630,45.7598},{133.890,45.1949},{136.150,44.0650},{138.409,42.9351},{140.669,41.8052},{142.929,40.6754},{145.188,39.5455},{147.448,38.4156},{149.708,37.2858},{151.968,36.7208},{154.227,35.5910},{156.487,35.5910},{158.747,35.5910},{161.007,34.4611},{163.266,34.4611},{165.526,34.4611},{167.786,34.4611},{170.046,34.4611},{172.305,33.3312},{174.565,32.7663},{176.825,32.2013},{179.085,32.2013},{181.344,32.2013},{183.604,32.7663},{185.864,33.3312}}
conica[2]={{0.565,23.1624},{2.825,23.1624},{5.084,23.7273},{7.344,24.2922},{9.604,24.2922},{11.864,24.2922},{14.123,24.2922},{16.383,24.2922},{18.643,24.8572},{20.903,26.5520},{23.162,29.3767},{25.422,32.7663},{27.682,36.1559},{29.942,39.5455},{32.201,41.8052},{34.461,42.9351},{36.721,44.0650},{38.981,44.6299},{41.240,45.1949},{43.500,45.1949},{45.760,44.6299},{48.020,44.6299},{50.279,44.6299},{52.539,43.5000},{54.799,42.3702},{57.059,40.1104},{59.318,36.7208},{61.578,31.6364},{63.838,25.9870},{66.097,23.7273},{68.357,21.4676},{70.617,19.2078},{72.877,16.9481},{75.136,15.8182},{77.396,14.1234},{79.656,12.4286},{81.916,11.2987},{84.175,9.6039},{86.435,9.0390},{88.695,7.3442},{90.955,6.2143},{93.214,5.6494},{95.474,6.2143},{97.734,6.2143},{99.994,6.2143},{102.253,7.3442},{104.513,7.9091},{106.773,10.1688},{109.033,11.2987},{111.292,13.5585}}
conica[3]={{0.565,12.9935},{2.825,12.9935},{5.084,12.9935},{7.344,14.1234},{9.604,15.2533},{11.864,16.9481},{14.123,18.0779},{16.383,22.0325},{18.643,24.8572},{20.903,28.2468},{23.162,31.6364},{25.422,35.0260},{27.682,36.7208},{29.942,37.8507},{32.201,38.4156},{34.461,38.9806},{36.721,38.9806},{38.981,38.9806},{41.240,38.9806},{43.500,37.8507},{45.760,36.1559},{48.020,35.0260},{50.279,32.2013},{52.539,28.2468},{54.799,25.4221},{57.059,21.4676},{59.318,19.2078},{61.578,18.0779},{63.838,16.9481},{66.097,15.8182},{68.357,15.2533},{70.617,14.1234},{72.877,15.2533},{75.136,14.1234},{77.396,15.2533},{79.656,15.2533},{81.916,16.9481},{84.175,19.2078},{86.435,21.4676},{88.695,25.4221},{90.955,28.2468},{93.214,31.6364},{95.474,32.7663},{97.734,33.8961},{99.994,35.0260},{102.253,35.5910},{104.513,35.5910},{106.773,35.5910},{109.033,35.0260},{111.292,33.3312},{113.552,32.7663},{115.812,30.5065},{118.072,27.1169},{120.331,22.0325},{122.591,17.5130},{124.851,14.1234},{127.111,11.2987},{129.370,9.0390},{131.630,7.3442},{133.890,7.3442},{136.150,8.4740},{138.409,9.6039},{140.669,9.6039},{142.929,9.6039},{145.188,9.0390},{147.448,7.3442}}
conica[4]={{0.5649,18.6429},{2.8247,17.5130},{5.0844,15.8182},{7.3442,14.1234},{9.6039,12.4286},{11.8636,11.8636},{14.1234,11.8636},{16.3831,12.9935},{18.6429,14.6883},{20.9026,16.9481},{23.1624,18.0779},{25.4221,20.3377},{27.6818,22.0325},{29.9416,23.7273},{32.2013,24.8572},{34.4611,27.1169},{36.7208,28.8117},{38.9806,30.5065},{41.2403,32.2013},{43.5000,32.7663},{45.7598,33.3312},{48.0195,34.4611},{50.2793,34.4611},{52.5390,34.4611},{54.7988,33.3312},{57.0585,32.7663},{59.3182,32.2013},{61.5780,30.5065},{63.8377,28.2468},{66.0975,25.9870},{68.3572,23.7273},{70.6170,20.3377},{72.8767,18.0779},{75.1364,15.8182},{77.3962,14.1234},{79.6559,12.9935},{81.9157,12.9935},{84.1754,14.1234},{86.4352,14.1234}}

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