115 lines
2.5 KiB
C
115 lines
2.5 KiB
C
|
#ifndef _FUNC_H
|
||
|
#define _FUNC_H
|
||
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <sstream>
|
||
|
#include <iomanip>
|
||
|
#include <cmath>
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#define OUTPUT "-o"
|
||
|
#define WGS84 "WGS84"
|
||
|
#define RADIUS "-d"
|
||
|
#define RANGE "-r"
|
||
|
#define INSERT "-i"
|
||
|
#define FILE "-f"
|
||
|
#define pole_radius 6356752.3//WGS84椭球极半径
|
||
|
#define equator_radius 6378137//WGS84椭球长半径
|
||
|
#define pi 3.1415926535897932384626433832795
|
||
|
using namespace std;
|
||
|
|
||
|
struct point3d
|
||
|
{
|
||
|
double x,y,z;
|
||
|
};
|
||
|
|
||
|
double WGS84_r(double lati)
|
||
|
{
|
||
|
return pole_radius*equator_radius/sqrt(pow(pole_radius,2)*pow(cos((double) lati*pi/180.0),2)+pow(equator_radius,2)*pow(sin((double) lati*pi/180.0),2));
|
||
|
}
|
||
|
|
||
|
point3d SCS2CCS(double phi,double thet,double radius)
|
||
|
{
|
||
|
point3d v;
|
||
|
v.x = radius*sin((0.5-thet/180.0)*pi)*cos((2.0+phi/180.0)*pi);
|
||
|
v.y = radius*sin((0.5-thet/180.0)*pi)*sin((2.0+phi/180.0)*pi);
|
||
|
v.z = radius*cos((0.5-thet/180.0)*pi);
|
||
|
return v;
|
||
|
}
|
||
|
|
||
|
int create_grid(double radius,int* interval,int* range,string outname)
|
||
|
{
|
||
|
point3d posi;
|
||
|
int d_phi = *interval,d_thet = *(interval+1);
|
||
|
int xmin = *range,xmax = *(range+1),ymin = *(range+2),ymax = *(range+3);
|
||
|
|
||
|
ofstream outfile(outname.c_str());
|
||
|
if (radius==-1.0)
|
||
|
{
|
||
|
for (int i = ymin; i <= ymax; i+=d_thet)
|
||
|
{
|
||
|
for (int j = xmin; j <= xmax; j+=d_phi)
|
||
|
{
|
||
|
posi = SCS2CCS(j,i,WGS84_r(i));
|
||
|
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
|
||
|
}
|
||
|
}
|
||
|
outfile.close();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
for (int i = ymin; i <= ymax; i+=d_thet)
|
||
|
{
|
||
|
for (int j = xmin; j <= xmax; j+=d_phi)
|
||
|
{
|
||
|
posi = SCS2CCS(j,i,radius);
|
||
|
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
|
||
|
}
|
||
|
}
|
||
|
outfile.close();
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int add_grid(double radius,string input_name,string output_name)
|
||
|
{
|
||
|
point3d posi;
|
||
|
string temp;
|
||
|
stringstream stemp;
|
||
|
double temp_phi,temp_thet,temp_radius;
|
||
|
ifstream infile(input_name.c_str());
|
||
|
ofstream outfile(output_name.c_str());
|
||
|
if (!infile)
|
||
|
{
|
||
|
cout<<input_name<<" not found, program stopped..."<<endl;
|
||
|
return 1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
while(getline(infile,temp)) {
|
||
|
if (temp!="")
|
||
|
{
|
||
|
stemp.clear();
|
||
|
stemp.str(temp);
|
||
|
stemp>>temp_phi>>temp_thet>>temp_radius;
|
||
|
}
|
||
|
|
||
|
if (radius==-1.0)
|
||
|
{
|
||
|
posi = SCS2CCS(temp_phi,temp_thet,WGS84_r(temp_thet)+temp_radius);
|
||
|
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
posi = SCS2CCS(temp_phi,temp_thet,radius+temp_radius);
|
||
|
outfile<<setprecision(16)<<posi.x<<" "<<posi.y<<" "<<posi.z<<endl;
|
||
|
}
|
||
|
}
|
||
|
infile.close();
|
||
|
outfile.close();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
#endif
|