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






	(*******************************  Ecbalium  *)

Needs["Splines`"]

Ecbalium[1]={{0.43703,0.00470},{0.45582,0.04229},{0.47462,0.11278},{0.49342,0.18797},{0.51221,0.27255},{0.53101,0.33364},{0.54981,0.39473},{0.56861,0.45582},{0.58740,0.49812},{0.60620,0.54041},{0.62500,0.59210},{0.64379,0.62969},{0.66259,0.66729},{0.68139,0.70018},{0.70018,0.73308},{0.71898,0.78007},{0.73778,0.81296},{0.75657,0.84116},{0.77537,0.86935},{0.79417,0.89755},{0.81296,0.92105},{0.83176,0.94454},{0.85056,0.96334},{0.86935,0.98684},{0.88815,1.01033},{0.90695,1.03383},{0.92575,1.05262},{0.94454,1.07142},{0.96334,1.09022},{0.98214,1.10901},{1.00093,1.13721},{1.01973,1.15131},{1.03853,1.16071},{1.05732,1.17480},{1.07612,1.18890},{1.09492,1.19830},{1.11371,1.21710},{1.13251,1.23119},{1.15131,1.24529},{1.17010,1.25469},{1.18890,1.26409},{1.20770,1.27349},{1.22650,1.28758},{1.24529,1.30168},{1.26409,1.31108},{1.28289,1.32048},{1.30168,1.32988},{1.32048,1.33928},{1.33928,1.34867},{1.35807,1.35807},{1.37687,1.37217},{1.39567,1.38627},{1.41446,1.39567},{1.43326,1.41446},{1.45206,1.42386},{1.47085,1.42856},{1.48965,1.43796},{1.50845,1.44266},{1.52724,1.44736},{1.54604,1.45206},{1.56484,1.46146},{1.58364,1.46616},{1.60243,1.46616},{1.62123,1.46616},{1.64003,1.46616},{1.65882,1.47085},{1.67762,1.47555},{1.69642,1.46616},{1.71521,1.46616},{1.73401,1.46616},{1.75281,1.46616},{1.77160,1.46616},{1.79040,1.46616},{1.80920,1.46616},{1.82799,1.46616},{1.84679,1.46616},{1.86559,1.46616},{1.88439,1.46616},{1.90318,1.46616},{1.92198,1.46616},{1.94078,1.46616},{1.95957,1.46616},{1.97837,1.46616},{1.99717,1.45676},{2.01596,1.45206},{2.03476,1.44266},{2.05356,1.42386},{2.07235,1.40976},{2.09115,1.38627},{2.10995,1.37687},{2.12874,1.36277},{2.14754,1.35337},{2.16634,1.34867},{2.18513,1.33928},{2.20393,1.32988},{2.22273,1.32988},{2.24153,1.32518},{2.26032,1.31578},{2.27912,1.31108},{2.29792,1.30168},{2.31671,1.28758},{2.33551,1.27819},{2.35431,1.27349},{2.37310,1.26879},{2.39190,1.26409},{2.41070,1.24999},{2.42949,1.24059},{2.44829,1.22650},{2.46709,1.21710},{2.48588,1.20300},{2.50468,1.18420},{2.52348,1.17010},{2.54228,1.15131},{2.56107,1.14191},{2.57987,1.12311},{2.59867,1.10432},{2.61746,1.09022},{2.63626,1.07142},{2.65506,1.05732},{2.67385,1.04792},{2.69265,1.02443},{2.71145,0.99623},{2.73024,0.97274},{2.74904,0.93984},{2.76784,0.91635},{2.78663,0.88815},{2.80543,0.85996},{2.82423,0.83176},{2.84302,0.80357},{2.86182,0.77537},{2.88062,0.73778},{2.89942,0.69548},{2.91821,0.66259},{2.93701,0.62500},{2.95581,0.58270},{2.97460,0.54511},{2.99340,0.49812},{3.01220,0.44173},{3.03099,0.38534},{3.04979,0.33834},{3.06859,0.21616},{3.06859,0.27725},{3.08738,0.13158},{3.08738,0.21146},{3.10618,0.00470},{3.10618,0.05639},{3.12498,0.00470}}
Ecbalium[2]={{0.28665,0.02350},{0.28665,0.07049},{0.28665,0.10338},{0.30545,0.06109},{0.30545,0.08459},{0.30545,0.16917},{0.30545,0.24436},{0.32425,0.27725},{0.34304,0.34774},{0.34304,0.41823},{0.36184,0.45112},{0.38064,0.52161},{0.39943,0.58270},{0.41823,0.62500},{0.43703,0.66729},{0.45582,0.70958},{0.47462,0.74718},{0.49342,0.79417},{0.51221,0.83176},{0.53101,0.86935},{0.54981,0.91165},{0.56861,0.93984},{0.58740,0.96334},{0.60620,1.00093},{0.62500,1.02913},{0.64379,1.04792},{0.66259,1.08082},{0.68139,1.11841},{0.70018,1.14661},{0.71898,1.16541},{0.73778,1.19360},{0.75657,1.22180},{0.77537,1.24529},{0.79417,1.26409},{0.81296,1.28758},{0.83176,1.30638},{0.85056,1.32048},{0.86935,1.33458},{0.88815,1.35337},{0.90695,1.38157},{0.92575,1.39567},{0.94454,1.40976},{0.96334,1.42386},{0.98214,1.44736},{1.00093,1.46146},{1.01973,1.47085},{1.03853,1.48495},{1.05732,1.49905},{1.07612,1.51785},{1.09492,1.53194},{1.11371,1.55074},{1.13251,1.56014},{1.15131,1.56954},{1.17010,1.59303},{1.18890,1.60243},{1.20770,1.61653},{1.22650,1.63063},{1.24529,1.64003},{1.26409,1.64942},{1.28289,1.66352},{1.30168,1.67292},{1.32048,1.68232},{1.33928,1.68702},{1.35807,1.69642},{1.37687,1.71051},{1.39567,1.72461},{1.41446,1.72931},{1.43326,1.73871},{1.45206,1.73871},{1.47085,1.74811},{1.48965,1.74811},{1.50845,1.75281},{1.52724,1.76221},{1.54604,1.76690},{1.56484,1.77160},{1.58364,1.78100},{1.60243,1.79040},{1.62123,1.79510},{1.64003,1.80450},{1.65882,1.80450},{1.67762,1.80450},{1.69642,1.80450},{1.71521,1.80450},{1.73401,1.81390},{1.75281,1.81390},{1.77160,1.81390},{1.79040,1.81390},{1.80920,1.81860},{1.82799,1.81390},{1.84679,1.81860},{1.86559,1.82330},{1.88439,1.82330},{1.90318,1.82330},{1.92198,1.82330},{1.94078,1.81390},{1.95957,1.80920},{1.97837,1.80450},{1.99717,1.79980},{2.01596,1.79040},{2.03476,1.78570},{2.05356,1.77630},{2.07235,1.77160},{2.09115,1.76221},{2.10995,1.75751},{2.12874,1.74811},{2.14754,1.74341},{2.16634,1.73401},{2.18513,1.72461},{2.20393,1.71051},{2.22273,1.69642},{2.24153,1.68702},{2.26032,1.67762},{2.27912,1.66822},{2.29792,1.65882},{2.31671,1.64942},{2.33551,1.64003},{2.35431,1.62593},{2.37310,1.61183},{2.39190,1.59773},{2.41070,1.58364},{2.42949,1.57424},{2.44829,1.55074},{2.46709,1.53194},{2.48588,1.51315},{2.50468,1.49435},{2.52348,1.48025},{2.54228,1.46616},{2.56107,1.44266},{2.57987,1.42386},{2.59867,1.40507},{2.61746,1.39097},{2.63626,1.37217},{2.65506,1.35337},{2.67385,1.33928},{2.69265,1.32518},{2.71145,1.31108},{2.73024,1.30638},{2.74904,1.30168},{2.76784,1.28758},{2.78663,1.25939},{2.80543,1.21710},{2.82423,1.17010},{2.84302,1.12781},{2.86182,1.09492},{2.88062,1.07142},{2.89942,1.05262},{2.91821,1.03383},{2.93701,1.00093},{2.95581,0.94454},{2.97460,0.89285},{2.99340,0.86466},{3.01220,0.84586},{3.03099,0.76127},{3.04979,0.65319},{3.06859,0.60150},{3.08738,0.55921},{3.10618,0.53101},{3.12498,0.50752},{3.14377,0.28195},{3.14377,0.46992},{3.16257,0.15507},{3.16257,0.38064},{3.18137,0.03759}}
Ecbalium[3]={{0.38064,0.00940},{0.39943,0.03759},{0.41823,0.08929},{0.43703,0.13158},{0.45582,0.15977},{0.47462,0.20207},{0.49342,0.25376},{0.51221,0.29605},{0.53101,0.34304},{0.54981,0.38064},{0.56861,0.41353},{0.58740,0.44173},{0.60620,0.47932},{0.62500,0.51221},{0.64379,0.54981},{0.66259,0.59680},{0.68139,0.62500},{0.70018,0.65789},{0.71898,0.68609},{0.73778,0.71428},{0.75657,0.74718},{0.77537,0.78007},{0.79417,0.80826},{0.81296,0.82236},{0.83176,0.83646},{0.85056,0.85526},{0.86935,0.88345},{0.88815,0.90225},{0.90695,0.93044},{0.92575,0.95394},{0.94454,0.98214},{0.96334,1.00563},{0.98214,1.02913},{1.00093,1.05262},{1.01973,1.07142},{1.03853,1.08552},{1.05732,1.10432},{1.07612,1.11371},{1.09492,1.12781},{1.11371,1.14661},{1.13251,1.17010},{1.15131,1.17950},{1.17010,1.18890},{1.18890,1.19360},{1.20770,1.21240},{1.22650,1.22650},{1.24529,1.23589},{1.26409,1.24999},{1.28289,1.26409},{1.30168,1.27349},{1.32048,1.28289},{1.33928,1.29228},{1.35807,1.30168},{1.37687,1.30638},{1.39567,1.31578},{1.41446,1.32988},{1.43326,1.34398},{1.45206,1.34867},{1.47085,1.36277},{1.48965,1.37217},{1.50845,1.37687},{1.52724,1.38157},{1.54604,1.38157},{1.56484,1.37687},{1.58364,1.35807},{1.60243,1.35337},{1.62123,1.34867},{1.64003,1.33928},{1.65882,1.32988},{1.67762,1.32518},{1.69642,1.32048},{1.71521,1.30638},{1.73401,1.29698},{1.75281,1.29228},{1.77160,1.28289},{1.79040,1.27349},{1.80920,1.26879},{1.82799,1.25939},{1.84679,1.24999},{1.86559,1.24059},{1.88439,1.23589},{1.90318,1.21710},{1.92198,1.20770},{1.94078,1.19360},{1.95957,1.17950},{1.97837,1.17010},{1.99717,1.16541},{2.01596,1.15131},{2.03476,1.13721},{2.05356,1.11841},{2.07235,1.10432},{2.09115,1.09022},{2.10995,1.08552},{2.12874,1.07612},{2.14754,1.06202},{2.16634,1.04323},{2.18513,1.02443},{2.20393,1.00563},{2.22273,0.98684},{2.24153,0.96804},{2.26032,0.94454},{2.27912,0.91635},{2.29792,0.88815},{2.31671,0.85996},{2.33551,0.83176},{2.35431,0.81296},{2.37310,0.78947},{2.39190,0.75657},{2.41070,0.72838},{2.42949,0.69548},{2.44829,0.67199},{2.46709,0.63439},{2.48588,0.59680},{2.50468,0.56861},{2.52348,0.53101},{2.54228,0.49342},{2.56107,0.45112},{2.57987,0.41823},{2.59867,0.39003},{2.61746,0.35244},{2.63626,0.30075},{2.65506,0.25846},{2.67385,0.21616},{2.69265,0.16917},{2.71145,0.11278},{2.73024,0.05169},{2.74904,0.01410},{2.76784,0.00470}}
Ecbalium[4]={{0.39943,0.00940},{0.39943,0.03759},{0.41823,0.02350},{0.41823,0.08929},{0.43703,0.15507},{0.45582,0.19267},{0.47462,0.24436},{0.49342,0.29605},{0.51221,0.33834},{0.53101,0.37594},{0.54981,0.42763},{0.56861,0.54041},{0.58740,0.64379},{0.60620,0.67669},{0.62500,0.70018},{0.64379,0.71898},{0.66259,0.73308},{0.68139,0.75187},{0.70018,0.77537},{0.71898,0.80826},{0.73778,0.84116},{0.75657,0.87875},{0.77537,0.89755},{0.79417,0.92575},{0.81296,0.96804},{0.83176,1.00563},{0.85056,1.02913},{0.86935,1.05262},{0.88815,1.08082},{0.90695,1.10901},{0.92575,1.13721},{0.94454,1.16071},{0.96334,1.18420},{0.98214,1.20770},{1.00093,1.22650},{1.01973,1.23589},{1.03853,1.24999},{1.05732,1.26879},{1.07612,1.28289},{1.09492,1.30168},{1.11371,1.31578},{1.13251,1.33458},{1.15131,1.34867},{1.17010,1.35807},{1.18890,1.37217},{1.20770,1.38627},{1.22650,1.39567},{1.24529,1.40976},{1.26409,1.41446},{1.28289,1.42386},{1.30168,1.44266},{1.32048,1.44736},{1.33928,1.45676},{1.35807,1.45676},{1.37687,1.45676},{1.39567,1.46616},{1.41446,1.46616},{1.43326,1.46616},{1.45206,1.46616},{1.47085,1.47085},{1.48965,1.48025},{1.50845,1.48965},{1.52724,1.50375},{1.54604,1.51785},{1.56484,1.52724},{1.58364,1.53664},{1.60243,1.54134},{1.62123,1.54604},{1.64003,1.55544},{1.65882,1.56014},{1.67762,1.56484},{1.69642,1.57424},{1.71521,1.57894},{1.73401,1.58364},{1.75281,1.59773},{1.77160,1.59303},{1.79040,1.59303},{1.80920,1.59773},{1.82799,1.59773},{1.84679,1.59303},{1.86559,1.58833},{1.88439,1.58833},{1.90318,1.58833},{1.92198,1.58833},{1.94078,1.57424},{1.95957,1.56954},{1.97837,1.56954},{1.99717,1.56484},{2.01596,1.56484},{2.03476,1.56484},{2.05356,1.56014},{2.07235,1.55074},{2.09115,1.53664},{2.10995,1.51785},{2.12874,1.50375},{2.14754,1.48495},{2.16634,1.47555},{2.18513,1.46146},{2.20393,1.43796},{2.22273,1.42856},{2.24153,1.40976},{2.26032,1.39567},{2.27912,1.38157},{2.29792,1.36747},{2.31671,1.34867},{2.33551,1.32518},{2.35431,1.28758},{2.37310,1.24059},{2.39190,1.18420},{2.41070,1.15601},{2.42949,1.13251},{2.44829,1.10901},{2.46709,1.09022},{2.48588,1.07142},{2.50468,1.04792},{2.52348,1.02443},{2.54228,1.00563},{2.56107,0.98214},{2.57987,0.96334},{2.59867,0.93514},{2.61746,0.91165},{2.63626,0.88815},{2.65506,0.85996},{2.67385,0.83176},{2.69265,0.79887},{2.71145,0.76597},{2.73024,0.73778},{2.74904,0.70018},{2.76784,0.65319},{2.78663,0.62030},{2.80543,0.58270},{2.82423,0.52631},{2.82423,0.55921},{2.84302,0.50752},{2.86182,0.47932},{2.88062,0.40883},{2.89942,0.32425},{2.91821,0.28665},{2.93701,0.25376},{2.95581,0.20677},{2.97460,0.14568},{2.99340,0.07989},{3.01220,0.02350},{3.03099,0.00470}}

(*Poner aqui la familia*)
var=Ecbalium;
(* el número de curvas estudiadas/semillas de la familia*)
m=6;
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[{curbe[j,t],0<t<1},t]];
vmed[j]=Abs[NIntegrate[curbe[j,t],{t,0,1}]];
dibcurbe[j]=Plot[{curbe[j,t],-vmed[j]},{t,0,1},PlotRange->{-5,10},DisplayFunction->Identity,PlotStyle->{RGBColor[0,1,0],{Dotted,Dashed}}];
total=GraphicsGrid[{
(*{spli,pp},*)
{dibez[j],dibcurbe[j]}},Spacings->0.3];
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,12}]];
Print["Valores medios de curvatura de cada ", var ," en [0,1]:  ", Table[vmed[j],{j,1,6}]];

Table[NMinValue[{curbe[j,t],0.25<t<0.75},t],{j,1,6}]

dibcurbe[j],{j,1,6}