add numerical recipes library

This commit is contained in:
2025-09-12 18:55:25 +09:00
parent d4dff245bd
commit 2c75620ec9
1344 changed files with 63869 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#include <cmath>
#include "nr.h"
using namespace std;
namespace {
inline DP alen(const DP a, const DP b, const DP c, const DP d)
{
return sqrt((b-a)*(b-a)+(d-c)*(d-c));
}
}
DP NR::revcst(Vec_I_DP &x, Vec_I_DP &y, Vec_I_INT &iorder, Vec_IO_INT &n)
{
int j,ii;
DP de;
Vec_DP xx(4),yy(4);
int ncity=x.size();
n[2]=(n[0]+ncity-1) % ncity;
n[3]=(n[1]+1) % ncity;
for (j=0;j<4;j++) {
ii=iorder[n[j]];
xx[j]=x[ii];
yy[j]=y[ii];
}
de = -alen(xx[0],xx[2],yy[0],yy[2]);
de -= alen(xx[1],xx[3],yy[1],yy[3]);
de += alen(xx[0],xx[3],yy[0],yy[3]);
de += alen(xx[1],xx[2],yy[1],yy[2]);
return de;
}