gctl_toolkits/archive/trackline/sysDefine.h
2024-09-10 20:25:18 +08:00

119 lines
2.6 KiB
C++

#ifndef _SYSDEFINE_H
#define _SYSDEFINE_H
#include "ctype.h"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "string.h"
#include "iostream"
#include "fstream"
#include "sstream"
#include "iomanip"
#include "vector"
#include "ctime"
#include "cmath"
#define ZERO 1.0e-16
#define BDL_MAX 1.0e+30
#define BDL_MIN -1.0e+30
#define BOLDRED "\033[1m\033[31m"
#define RESET "\033[0m"
#define pi (4.0*atan(1.0))
using namespace std;
typedef vector<int> _1iArray;
typedef vector<vector<int> > _2iArray;
typedef vector<double> _1dArray;
int open_infile(ifstream &infile,char* filename)
{
infile.open(filename);
if (!infile)
{
cout << BOLDRED << "error ==> " << RESET << "file not found: " << filename << endl;
return -1;
}
return 0;
}
int open_outfile(ofstream &outfile,char* filename)
{
outfile.open(filename);
if (!outfile)
{
cout << BOLDRED << "error ==> " << RESET << "fail to create the file: " << filename << endl;
return -1;
}
return 0;
}
struct node2d
{
int id;
double px; //切割剖面上的二维横纵坐标值
double x,y; //在球坐标数据插值中 x y值对应经纬度 z值对应深度
double val; //目前只允许每个点附带一个数据值
node2d()
{
id = -1;
x = y = val = BDL_MAX;
px = BDL_MAX;
}
void info()
{
cout << id << " " << x << " " << y << " " << px << " " << val << endl;
}
};
typedef vector<node2d> node2dArray;
double node2dDistance(node2d n1,node2d n2)
{
return sqrt(pow(n2.x-n1.x,2)+pow(n2.y-n1.y,2));
}
//规则网络插值 长方形内数据插值 距离平方反比
/*长方体示意图*/
// y
// |
// |
// 3------------2
// | |
// | |
// | |
// 0------------1--->x
// 左下角坐标x0 y0
// 块体尺寸dx dy
// 插值点坐标x y
// 四个角点值
double interRectDist(double x0,double y0,double dx,double dy,double x,double y,
double d0,double d1,double d2,double d3)
{
double res = 0;
double total_dist = 0;
double dist[4] = {0,0,0,0};
double val[4];
val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3;
//检查四个角点值 如果有一个角点值为1e+30 则无法插值 返回插值点值为1e+30
for (int i = 0; i < 4; i++)
{
if (val[i] == BDL_MAX)
{
return BDL_MAX;
}
}
dist[0] = 1.0/(1e-30+(x-x0)*(x-x0)+(y-y0)*(y-y0));
dist[1] = 1.0/(1e-30+(x-dx-x0)*(x-dx-x0)+(y-y0)*(y-y0));
dist[2] = 1.0/(1e-30+(x-dx-x0)*(x-dx-x0)+(y-dy-y0)*(y-dy-y0));
dist[3] = 1.0/(1e-30+(x-x0)*(x-x0)+(y-dy-y0)*(y-dy-y0));
for (int i = 0; i < 4; i++)
{
total_dist += dist[i];
}
for (int i = 0; i < 4; i++)
{
res += val[i]*dist[i]/total_dist;
}
return res;
}
#endif