add numerical recipes library
This commit is contained in:
25
lib/nr/k_and_r/recipes/revcst.c
Normal file
25
lib/nr/k_and_r/recipes/revcst.c
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#include <math.h>
|
||||
#define ALEN(a,b,c,d) sqrt(((b)-(a))*((b)-(a))+((d)-(c))*((d)-(c)))
|
||||
|
||||
float revcst(x,y,iorder,ncity,n)
|
||||
float x[],y[];
|
||||
int iorder[],n[],ncity;
|
||||
{
|
||||
float xx[5],yy[5],de;
|
||||
int j,ii;
|
||||
|
||||
n[3]=1 + ((n[1]+ncity-2) % ncity);
|
||||
n[4]=1 + (n[2] % ncity);
|
||||
for (j=1;j<=4;j++) {
|
||||
ii=iorder[n[j]];
|
||||
xx[j]=x[ii];
|
||||
yy[j]=y[ii];
|
||||
}
|
||||
de = -ALEN(xx[1],xx[3],yy[1],yy[3]);
|
||||
de -= ALEN(xx[2],xx[4],yy[2],yy[4]);
|
||||
de += ALEN(xx[1],xx[4],yy[1],yy[4]);
|
||||
de += ALEN(xx[2],xx[3],yy[2],yy[3]);
|
||||
return de;
|
||||
}
|
||||
#undef ALEN
|
||||
Reference in New Issue
Block a user