空间直角坐标系(xyz)与大地坐标系(经纬高)的转换
程序员文章站
2022-04-03 23:21:13
...
//空间直角坐标系(xyz)转换大地坐标系(经纬度)
double a = 6378137.000;//长半轴
double f = 1 / 298.3;//扁率
double b = a - a * f;//短半轴
double ec = 1 - Math.pow(b, 2) / Math.pow(a, 2);//第一偏心率平方
double ecc= ec / (1-ec);//第二偏心率平方
double X =-2098813.2676;
double Y =4804967.1055;
double Z =3619537.1465;
double L = Math.atan(Y / X);
if (X < 0)
L += Math.PI;
double r = Math.sqrt(X * X + Y * Y);
double B1 = Math.atan(Z / r);
double B2;
while (true)
{
double W1 = Math.sqrt(1 - ec * (Math.sin(B1) * Math.sin(B1)));
double N1 = a / W1;
B2 = Math.atan((Z + N1 * ec * Math.sin(B1)) / r);
if (Math.abs(B2 - B1) <= 0.0000000001)
break;
B1 = B2;
}
double B = B2;
double W = Math.sqrt(1 - ec * (Math.sin(B2) * Math.sin(B2)));
double N = a / W;
double H = r / Math.cos(B2) - N;
System.out.println(L+","+B+","+H);
//大地坐标系(经纬度)转换空间直角坐标系(xyz)
double L=113.608437;
double B=34.802459;
double Height=0;
double a = 6378137.0;
double e2 = 0.00669438002290; //转换为弧度
L = L * PI/180;//经度
B = B * PI/180;//纬度
double fac1 = 1- e2*Math.sin(B)*Math.sin(B);
double N = a/Math.sqrt(fac1); //卯酉圈曲率半径
double Daita_h = 0; //高程异常,默认为0
double h = Daita_h + Height;
double X = (N+h)*Math.cos(B)*Math.cos(L);
double Y = (N+h)*Math.cos(B)*Math.sin(L);
double Z = ( N*(1-e2)+ h ) * Math.sin(B);
System.out.println(X+","+Y+","+Z);
下一篇: OpenGL坐标系相关