(*  The following are examples of curvature analysis  in seeds of  Vitis*)






	(*******************************   ferral*)

Needs["Splines`"]

ferral[1]={{0.79837,5.00518},{0.85978,5.71143},{0.9212,5.89567},{0.98261,6.01849},{1.04402,6.14132},{1.10544,6.26415},{1.16685,6.38697},{1.22826,6.47909},{1.28968,6.54051},{1.35109,6.60192},{1.4125,6.66333},{1.47392,6.72475},{1.53533,6.78616},{1.59674,6.81686},{1.65816,6.84757},{1.71957,6.87828},{1.78098,6.87828},{1.8424,6.90898},{1.90381,6.93969},{1.96522,6.93969},{2.02664,6.93969},{2.08805,6.93969},{2.14946,6.93969},{2.21088,6.93969},{2.27229,6.90898},{2.3337,6.87828},{2.39511,6.87828},{2.45653,6.87828},{2.51794,6.84757},{2.57935,6.81686},{2.64077,6.78616},{2.70218,6.75545},{2.76359,6.78616},{2.82501,6.81686},{2.88642,6.84757},{2.94783,6.87828},{3.00925,6.87828},{3.07066,6.90898},{3.13207,6.93969},{3.19349,6.93969},{3.2549,6.9704},{3.31631,7.0011},{3.37773,7.0011},{3.43914,7.0011},{3.50055,7.0011},{3.56197,7.0011},{3.62338,6.9704},{3.68479,6.93969},{3.74621,6.93969},{3.80762,6.90898},{3.86903,6.87828},{3.93044,6.84757},{3.99186,6.81686},{4.05327,6.75545},{4.11468,6.69404},{4.1761,6.66333},{4.23751,6.60192},{4.29892,6.54051},{4.36034,6.44839},{4.42175,6.35627},{4.48316,6.26415},{4.54458,6.14132},{4.60599,5.98779},{4.6674,5.83425},{4.72882,5.68072},{4.79023,5.49648},{4.85164,5.00518},{4.79023,4.42175},{4.72882,4.14539},{4.6674,3.99186},{4.60599,3.86903},{4.54458,3.74621},{4.48316,3.62338},{4.42175,3.53126},{4.36034,3.46985},{4.29892,3.37773},{4.23751,3.28561},{4.1761,3.22419},{4.11468,3.13207},{4.05327,3.03995},{3.99186,2.97854},{3.93044,2.88642},{3.86903,2.73289},{3.80762,1.8424},{3.74621,0.98261},{3.68479,0.89049},{3.62338,0.85978},{3.56197,0.82908},{3.50055,0.79837},{3.43914,0.76766},{3.37773,0.70625},{3.31631,0.67555},{3.2549,0.67555},{3.19349,0.67555},{3.13207,0.67555},{3.07066,0.64484},{3.00925,0.61413},{2.94783,0.61413},{2.88642,0.58343},{2.82501,0.55272},{2.76359,0.55272},{2.70218,0.55272},{2.64077,0.58343},{2.57935,0.61413},{2.51794,0.61413},{2.45653,0.64484},{2.39511,0.70625},{2.3337,0.79837},{2.27229,0.9212},{2.21088,1.25897},{2.14946,1.62745},{2.08805,1.81169},{2.02664,2.11876},{1.96522,2.39511},{1.90381,2.51794},{1.8424,2.64077},{1.78098,2.73289},{1.71957,2.82501},{1.65816,2.91713},{1.59674,2.97854},{1.53533,3.07066},{1.47392,3.16278},{1.4125,3.22419},{1.35109,3.31631},{1.28968,3.43914},{1.22826,3.56197},{1.16685,3.65409},{1.10544,3.74621},{1.04402,3.89974},{0.98261,4.05327},{0.9212,4.1761},{0.85978,4.32963}}
ferral[2]={{0.9212,5.28154},{0.98261,5.52719},{1.04402,5.71143},{1.10544,5.83425},{1.16685,5.95708},{1.22826,6.0492},{1.28968,6.11061},{1.35109,6.20273},{1.4125,6.26415},{1.47392,6.29485},{1.53533,6.35627},{1.59674,6.38697},{1.65816,6.41768},{1.71957,6.47909},{1.78098,6.5098},{1.8424,6.54051},{1.90381,6.57121},{1.96522,6.57121},{2.02664,6.60192},{2.08805,6.63263},{2.14946,6.63263},{2.21088,6.63263},{2.27229,6.60192},{2.3337,6.57121},{2.39511,6.57121},{2.45653,6.54051},{2.51794,6.5098},{2.57935,6.5098},{2.64077,6.5098},{2.70218,6.5098},{2.76359,6.5098},{2.82501,6.47909},{2.88642,6.47909},{2.94783,6.5098},{3.00925,6.5098},{3.07066,6.54051},{3.13207,6.60192},{3.19349,6.63263},{3.2549,6.63263},{3.31631,6.63263},{3.37773,6.63263},{3.43914,6.63263},{3.50055,6.63263},{3.56197,6.63263},{3.62338,6.63263},{3.68479,6.63263},{3.74621,6.63263},{3.80762,6.60192},{3.86903,6.57121},{3.93044,6.57121},{3.99186,6.54051},{4.05327,6.47909},{4.11468,6.44839},{4.1761,6.41768},{4.23751,6.35627},{4.29892,6.29485},{4.36034,6.23344},{4.42175,6.17203},{4.48316,6.11061},{4.54458,6.01849},{4.60599,5.89567},{4.6674,5.77284},{4.72882,5.61931},{4.79023,5.28154},{4.85164,4.82094},{4.79023,4.32963},{4.72882,4.05327},{4.6674,3.86903},{4.60599,3.74621},{4.54458,3.59267},{4.48316,3.46985},{4.42175,3.37773},{4.36034,3.2549},{4.29892,3.13207},{4.23751,3.03995},{4.1761,2.94783},{4.11468,2.85571},{4.05327,2.76359},{3.99186,2.67147},{3.93044,2.57935},{3.86903,2.48723},{3.80762,2.36441},{3.74621,0.9519},{3.68479,0.85978},{3.62338,0.76766},{3.56197,0.70625},{3.50055,0.67555},{3.43914,0.67555},{3.37773,0.64484},{3.31631,0.61413},{3.2549,0.61413},{3.19349,0.61413},{3.13207,0.61413},{3.07066,0.61413},{3.00925,0.64484},{2.94783,0.64484},{2.88642,0.61413},{2.82501,0.61413},{2.76359,0.61413},{2.70218,0.61413},{2.64077,0.61413},{2.57935,0.61413},{2.51794,0.61413},{2.45653,0.64484},{2.39511,0.67555},{2.3337,0.70625},{2.27229,0.73696},{2.21088,0.79837},{2.14946,0.9519},{2.08805,1.28968},{2.02664,1.90381},{1.96522,2.36441},{1.90381,2.48723},{1.8424,2.57935},{1.78098,2.67147},{1.71957,2.76359},{1.65816,2.85571},{1.59674,2.91713},{1.53533,2.97854},{1.47392,3.03995},{1.4125,3.10137},{1.35109,3.19349},{1.28968,3.28561},{1.22826,3.37773},{1.16685,3.50055},{1.10544,3.62338},{1.04402,3.77691},{0.98261,3.99186},{0.9212,4.26822},{0.85978,4.79023}}
ferral[3]={{0.30707,5.25083},{0.36848,5.52719},{0.42989,5.68072},{0.49131,5.80355},{0.55272,5.86496},{0.61413,5.92637},{0.67555,5.98779},{0.73696,6.0492},{0.79837,6.11061},{0.85978,6.17203},{0.9212,6.20273},{0.98261,6.23344},{1.04402,6.29485},{1.10544,6.32556},{1.16685,6.35627},{1.22826,6.38697},{1.28968,6.38697},{1.35109,6.38697},{1.4125,6.41768},{1.47392,6.44839},{1.53533,6.44839},{1.59674,6.44839},{1.65816,6.41768},{1.71957,6.38697},{1.78098,6.38697},{1.8424,6.38697},{1.90381,6.35627},{1.96522,6.35627},{2.02664,6.38697},{2.08805,6.38697},{2.14946,6.38697},{2.21088,6.38697},{2.27229,6.38697},{2.3337,6.38697},{2.39511,6.41768},{2.45653,6.44839},{2.51794,6.47909},{2.57935,6.5098},{2.64077,6.5098},{2.70218,6.5098},{2.76359,6.5098},{2.82501,6.5098},{2.88642,6.47909},{2.94783,6.44839},{3.00925,6.44839},{3.07066,6.44839},{3.13207,6.41768},{3.19349,6.38697},{3.2549,6.38697},{3.31631,6.35627},{3.37773,6.32556},{3.43914,6.29485},{3.50055,6.23344},{3.56197,6.17203},{3.62338,6.11061},{3.68479,6.0492},{3.74621,5.95708},{3.80762,5.86496},{3.86903,5.77284},{3.93044,5.61931},{3.99186,5.46577},{4.05327,5.28154},{4.11468,4.79023},{4.05327,4.23751},{3.99186,3.96115},{3.93044,3.74621},{3.86903,3.59267},{3.80762,3.43914},{3.74621,3.28561},{3.68479,3.19349},{3.62338,3.07066},{3.56197,2.97854},{3.50055,2.91713},{3.43914,2.85571},{3.37773,2.73289},{3.31631,2.54865},{3.2549,2.11876},{3.19349,1.07473},{3.13207,0.98261},{3.07066,0.85978},{3.00925,0.79837},{2.94783,0.76766},{2.88642,0.73696},{2.82501,0.73696},{2.76359,0.70625},{2.70218,0.67555},{2.64077,0.64484},{2.57935,0.61413},{2.51794,0.61413},{2.45653,0.61413},{2.39511,0.61413},{2.3337,0.61413},{2.27229,0.61413},{2.21088,0.61413},{2.14946,0.61413},{2.08805,0.61413},{2.02664,0.61413},{1.96522,0.61413},{1.90381,0.61413},{1.8424,0.64484},{1.78098,0.67555},{1.71957,0.67555},{1.65816,0.70625},{1.59674,0.73696},{1.53533,0.76766},{1.47392,0.89049},{1.4125,1.22826},{1.35109,1.78098},{1.28968,2.39511},{1.22826,2.57935},{1.16685,2.67147},{1.10544,2.73289},{1.04402,2.7943},{0.98261,2.85571},{0.9212,2.94783},{0.85978,3.03995},{0.79837,3.10137},{0.73696,3.16278},{0.67555,3.2549},{0.61413,3.34702},{0.55272,3.43914},{0.49131,3.59267},{0.42989,3.74621},{0.36848,3.99186},{0.30707,4.75952}}

(*Poner aqui la familia*)
var=ferral
(* el número de curvas estudiadas/semillas de la familia*)
m=3;
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_]=(BX'[t]BY''[t]-BX''[t]BY'[t])/((BX'[t])^2+(BY'[t])^2)^(3/2);
cur[j]=Abs[NMinValue[SetPrecision[{curbe[j,t],0.1<t<1},50],t,WorkingPrecision->8]];
vmed[j]=Abs[NIntegrate[curbe[j,t],{t,0.2,0.8}]];
dibcurbe[j]=Plot[{curbe[j,t],vmed[j]},{t,0,1},PlotRange->{-4,4},DisplayFunction->Identity,PlotStyle->{RGBColor[0,1,0],{Dotted,Dashed}}];
total=GraphicsGrid[{
(*{spli,pp},*)
{Print[""],dibez[j],dibcurbe[j]}},Spacings->0.5];
Print[var,j, ":", "Máximo valor de la curvatura (en valor absoluto)",cur[j]];
Print[total]
]
Print["Curvaturas de cada ", var ,":  ", Table[cur[j],{j,1,3}]];
Print["Valores medios de curvatura de cada ", var ," en [0.1,0.9]:  ", Table[vmed[j],{j,1,3}]];