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






	(*******************************  Sumoll*)

Needs["Splines`"]

Sumoll[1]={{0.8312,4.98721},{0.89514,4.63555},{0.95908,4.41176},{1.02302,4.28389},{1.08696,4.15601},{1.1509,4.02813},{1.21483,3.86829},{1.27877,3.70844},{1.34271,3.58056},{1.40665,3.45269},{1.47059,3.32481},{1.53453,3.13299},{1.59847,2.90921},{1.6624,2.65345},{1.72634,2.36573},{1.79028,2.14194},{1.85422,1.9821},{1.91816,1.85422},{1.9821,1.75831},{2.04604,1.72634},{2.10997,1.72634},{2.17391,1.72634},{2.23785,1.72634},{2.30179,1.69437},{2.36573,1.6624},{2.42967,1.6624},{2.49361,1.6624},{2.55754,1.69437},{2.62148,1.72634},{2.68542,1.75831},{2.74936,1.82225},{2.8133,1.95013},{2.87724,2.36573},{2.94118,2.90921},{3.00512,3.16496},{3.06905,3.29284},{3.13299,3.42072},{3.19693,3.51662},{3.26087,3.6445},{3.32481,3.74041},{3.38875,3.83632},{3.45269,3.96419},{3.51662,4.09207},{3.58056,4.25192},{3.6445,4.41176},{3.70844,4.57161},{3.77238,4.85933},{3.83632,5.27494},{3.90026,5.65857},{3.83632,6.07417},{3.77238,6.39386},{3.70844,6.52174},{3.6445,6.61765},{3.58056,6.71355},{3.51662,6.80946},{3.45269,6.8734},{3.38875,6.93734},{3.32481,6.96931},{3.26087,7.00128},{3.19693,7.03325},{3.13299,7.03325},{3.06905,7.06522},{3.00512,7.09719},{2.94118,7.09719},{2.87724,7.09719},{2.8133,7.12916},{2.74936,7.16113},{2.68542,7.16113},{2.62148,7.16113},{2.55754,7.16113},{2.49361,7.16113},{2.42967,7.16113},{2.36573,7.16113},{2.30179,7.16113},{2.23785,7.16113},{2.17391,7.16113},{2.10997,7.19309},{2.04604,7.22506},{1.9821,7.22506},{1.91816,7.19309},{1.85422,7.16113},{1.79028,7.12916},{1.72634,7.09719},{1.6624,7.06522},{1.59847,7.03325},{1.53453,7.00128},{1.47059,6.93734},{1.40665,6.8734},{1.34271,6.77749},{1.27877,6.68159},{1.21483,6.55371},{1.1509,6.39386},{1.08696,6.26598},{1.02302,6.10614},{0.95908,5.91432},{0.89514,5.49872}}
Sumoll[2]={{1.08696,6.17008},{1.1509,6.71355},{1.21483,7.03325},{1.27877,7.22506},{1.34271,7.35294},{1.40665,7.44885},{1.47059,7.51279},{1.53453,7.57673},{1.59847,7.64067},{1.6624,7.67263},{1.72634,7.7046},{1.79028,7.73657},{1.85422,7.73657},{1.91816,7.76854},{1.9821,7.80051},{2.04604,7.80051},{2.10997,7.80051},{2.17391,7.80051},{2.23785,7.80051},{2.30179,7.80051},{2.36573,7.80051},{2.42967,7.80051},{2.49361,7.80051},{2.55754,7.80051},{2.62148,7.80051},{2.68542,7.80051},{2.74936,7.80051},{2.8133,7.80051},{2.87724,7.80051},{2.94118,7.80051},{3.00512,7.80051},{3.06905,7.80051},{3.13299,7.80051},{3.19693,7.80051},{3.26087,7.76854},{3.32481,7.73657},{3.38875,7.73657},{3.45269,7.7046},{3.51662,7.67263},{3.58056,7.64067},{3.6445,7.57673},{3.70844,7.51279},{3.77238,7.44885},{3.83632,7.35294},{3.90026,7.22506},{3.96419,7.09719},{4.02813,6.8734},{4.09207,6.42583},{4.15601,5.97826},{4.09207,5.53069},{4.02813,5.11509},{3.96419,4.8913},{3.90026,4.73146},{3.83632,4.60358},{3.77238,4.4757},{3.70844,4.34783},{3.6445,4.25192},{3.58056,4.15601},{3.51662,4.0601},{3.45269,3.96419},{3.38875,3.83632},{3.32481,3.70844},{3.26087,3.51662},{3.19693,3.29284},{3.13299,3.03708},{3.06905,2.78133},{3.00512,2.62148},{2.94118,2.49361},{2.87724,2.3977},{2.8133,2.36573},{2.74936,2.36573},{2.68542,2.33376},{2.62148,2.30179},{2.55754,2.30179},{2.49361,2.30179},{2.42967,2.30179},{2.36573,2.30179},{2.30179,2.30179},{2.23785,2.30179},{2.17391,2.33376},{2.10997,2.3977},{2.04604,2.46164},{1.9821,2.90921},{1.91816,3.45269},{1.85422,3.70844},{1.79028,3.90026},{1.72634,4.02813},{1.6624,4.12404},{1.59847,4.21995},{1.53453,4.34783},{1.47059,4.50767},{1.40665,4.66752},{1.34271,4.82737},{1.27877,5.01918},{1.21483,5.24297},{1.1509,5.59463}}
Sumoll[3]={{1.08696,5.85038},{1.1509,5.211},{1.21483,4.92327},{1.27877,4.7954},{1.34271,4.66752},{1.40665,4.53964},{1.47059,4.41176},{1.53453,4.31586},{1.59847,4.21995},{1.6624,4.12404},{1.72634,4.0601},{1.79028,3.96419},{1.85422,3.86829},{1.91816,3.74041},{1.9821,3.54859},{2.04604,3.29284},{2.10997,2.97315},{2.17391,2.62148},{2.23785,2.3977},{2.30179,2.33376},{2.36573,2.30179},{2.42967,2.30179},{2.49361,2.30179},{2.55754,2.30179},{2.62148,2.30179},{2.68542,2.30179},{2.74936,2.30179},{2.8133,2.26982},{2.87724,2.23785},{2.94118,2.23785},{3.00512,2.23785},{3.06905,2.23785},{3.13299,2.26982},{3.19693,2.33376},{3.26087,2.49361},{3.32481,2.8133},{3.38875,3.19693},{3.45269,3.51662},{3.51662,3.70844},{3.58056,3.83632},{3.6445,3.99616},{3.70844,4.12404},{3.77238,4.21995},{3.83632,4.34783},{3.90026,4.44373},{3.96419,4.60358},{4.02813,4.82737},{4.09207,5.01918},{4.15601,5.30691},{4.21995,5.75448},{4.15601,6.20205},{4.09207,6.52174},{4.02813,6.74552},{3.96419,6.96931},{3.90026,7.16113},{3.83632,7.289},{3.77238,7.38491},{3.70844,7.44885},{3.6445,7.51279},{3.58056,7.57673},{3.51662,7.6087},{3.45269,7.64067},{3.38875,7.7046},{3.32481,7.73657},{3.26087,7.73657},{3.19693,7.76854},{3.13299,7.80051},{3.06905,7.80051},{3.00512,7.80051},{2.94118,7.80051},{2.87724,7.80051},{2.8133,7.76854},{2.74936,7.73657},{2.68542,7.73657},{2.62148,7.73657},{2.55754,7.73657},{2.49361,7.73657},{2.42967,7.73657},{2.36573,7.73657},{2.30179,7.73657},{2.23785,7.7046},{2.17391,7.67263},{2.10997,7.67263},{2.04604,7.67263},{1.9821,7.67263},{1.91816,7.64067},{1.85422,7.6087},{1.79028,7.6087},{1.72634,7.57673},{1.6624,7.51279},{1.59847,7.48082},{1.53453,7.41688},{1.47059,7.32097},{1.40665,7.25703},{1.34271,7.16113},{1.27877,7.00128},{1.21483,6.74552},{1.1509,6.42583}}

(*Poner aqui la familia*)
var=Sumoll;
(* 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[NMaxValue[{curbe[j,t],0.2<t<1},t]];
vmed[j]=Abs[NIntegrate[curbe[j,t],{t,0.2,0.8}]];
dibcurbe[j]=Plot[{curbe[j,t],vmed[j]},{t,0,1},PlotRange->{-10,10},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}]];