编写了几个坐标系间相互转换的程序,其中包括了空间直角坐标系(CartesianCoor)和大地坐标系(GeodeticCoor)的两个类,分别在两个类中声明了转换到另一个坐标系的函数toCartesian和toGeodetic,但在编写toGeodetic函数时,却遇到
E0147 声明与 "<error-type> CartesianCoor::toGeodetic(Ellipsoid elp = CGCS2000, double eps = (((1.000000000000000082e-05) / (3600)) * PI) / (180))" (已声明 所在行数:74) 不兼容
的错误,但是类似的另外一个函数toCartesian却没有这样的问题。
/*需要完成:
坐标系转换,时间系统转换
另外需要矩阵运算库*/
#include <iostream>
#include <Eigen/Dense>
#include <vector>
const double PI = 3.141592653589793;
//表示特定椭球的结构体
/*struct ellipsoid
{
double a;
double e;
ellipsoid(double a, double e) : a(a), e(e) {}
};*/
//椭球类
class Ellipsoid
{
public:
double a;
double b;
double e;
double alpha;
double e_prime;
public:
Ellipsoid(double a, double b, double e, double alpha);//不提供的参数使用负值输入
};
Ellipsoid::Ellipsoid(double a_p, double b_p, double e_p, double alpha_p)
:a(a_p),b(b_p),e(e_p),alpha(alpha_p)
{
if (a > 0 && b > 0)
{
alpha = (a - b) / a;
e = sqrt((a * a - b * b) / (a * a));
}
else if (a > 0 && e > 0)
{
b = a * sqrt(1 - e * e);
alpha = (a - b) / a;
}
else if (a > 0 && alpha > 0)
{
e = 2 * alpha - alpha * alpha;
b = a * sqrt(1 - e * e);
}
else
{
a = 0; b = 0; e = 0; alpha = 0; e_prime = 0;
return;
}
e_prime = sqrt((a * a - b * b) / (b * b));
}
//一些常用的椭球
const Ellipsoid WGS84(6378137, -1, -1, 1 / 298.257223563);
const Ellipsoid Krassovsky(6378245,-1,-1,1 / 298.3);
const Ellipsoid CGCS2000(6378137, -1, -1, 1 / 298.257222101);
//空间直角坐标系
class CartesianCoor
{
private:
double x;
double y;
double z;
public:
CartesianCoor(double x_p, double y_p, double z_p) :x(x_p), y(y_p), z(z_p) {}
//SphericalCoor toSpherical();
GeodeticCoor toGeodetic(Ellipsoid elp = CGCS2000, double eps = 0.00001 / 3600 * PI / 180);
void look();
};
void CartesianCoor::look()
{
std::cout << "x = " << x << "\ny = " << y << "\nz = " << z << std::endl;
}
//球面坐标系
class SphericalCoor
{
private:
double d;
double alpha;
double sigma;
public:
CartesianCoor toCartesian();
};
//大地坐标系
class GeodeticCoor
{
private:
double B;
double L;
double H;
Ellipsoid elp;
public:
GeodeticCoor(double B_p, double L_p, double H_p, Ellipsoid elp_p=CGCS2000) :
B(B_p), L(L_p), H(H_p), elp(elp_p) {}
CartesianCoor toCartesian();
};
GeodeticCoor CartesianCoor::toGeodetic(Ellipsoid elp=CGCS2000,double eps=0.00001/3600*PI/180)//直角坐标系转大地坐标系(XYZtoBLH)
{
//迭代求解
double L = atan(y / x);
double B0 = atan(z / (x * x + y * y));
double B = B0;
double W;
double N;
do
{
B0 = B;
W = sqrt(1 - elp.e * elp.e * sin(B) * sin(B));
N = elp.a / W;
B = atan((z + N * elp.e * elp.e * sin(B)) / sqrt(x * x + y * y));
} while (abs(B - B0) < eps);
double H = z / sin(B) - N * (1 - elp.e * elp.e);
GeodeticCoor geodeticCoor(B, L, H);
return geodeticCoor;
}
CartesianCoor GeodeticCoor::toCartesian()//大地坐标系转直角坐标系(BLHtoXYZ)
{
double W = sqrt(1 - elp.e* elp.e * sin(B) * sin(B));
double N = elp.a / W;
double X = N * cos(B) * cos(L);
double Y = N * cos(B) * sin(L);
double Z = N * (1 - elp.e * elp.e) * sin(B);
CartesianCoor cartesianCoor(X, Y, Z);
return cartesianCoor;
}
void EigenPractice()
{
std::cout << "Basic constraction and calculation: " << std::endl;//基本操作
Eigen::MatrixXd m = Eigen::MatrixXd::Random(3, 3);//random values between -1 and 1
m = (m + Eigen::MatrixXd::Constant(3, 3, 1.2)) * 50;//3-by-3 matrix, all coefficients equal to 1.2
std::cout << "m=" << std::endl << m << std::endl;
Eigen::VectorXd v(3);
v << 1, 2, 3;
std::cout << "m*v=" << std::endl << m * v << std::endl;
std::cout << "more operations; " << std::endl;//更多操作
Eigen::MatrixXf m1(3, 4);
Eigen::Matrix3f mE;
m1 = Eigen::MatrixXf::Zero(3, 4);//全0矩阵
mE = Eigen::Matrix3f::Identity();//单位阵
std::cout << "m1:" << std::endl << m1 << std::endl;
std::cout << "mE:" << std::endl << mE << std::endl;
//后面做更多的操作
}
void Bursa_transformation()
{
//????
}
/*
Eigen::Vector3d BLH2XYZ(double a,double e,double B, double L, double H)
{
double W = sqrt(1 - e * e * sin(B) * sin(B));
double M = a * (1 - e * e) / (W * W * W);
double N = a / W;
Eigen::Vector3d XYZ;
XYZ(0) = N * cos(B) * cos(L);
XYZ(1) = N * cos(B) * sin(L);
XYZ(2) = N * (1 - e * e) * sin(B);
return XYZ;
}
Eigen::Vector3d XYZ2BLH(ellipsoid earth,Eigen::Vector3d XYZ)
{
Eigen::Vector3d BLH;
double X = XYZ(0);
double Y = XYZ(1);
double Z = XYZ(2);
BLH(1) = atan(Y / X);
//没写完,先回去复习C++,重新设计一下数据结构
return BLH;
}*/
//为
struct ephemeris
{
double satprn,
Toc,
a0,
a1,
a2,
IODE,
Crs,
DetaN,
M0,
Cuc,
e,
Cus,
sqrtA,
Toe,
Cic,
OMG0,
I0,
Crc,
omg,
OMG0dot,
I0dot,
GpsWn,
SatAccu,
SatHth,
Tgd;
};
int main()
{
GeodeticCoor BLH(0, PI/2, 10000000);
BLH.toCartesian().look();
return 0;
}