在Java中ECEF到lla(lat,lon,alt) [英] ECEF to lla (lat,lon,alt) in java

查看:197
本文介绍了在Java中ECEF到lla(lat,lon,alt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了网站上的帖子,并没有发现我的问题...
作为头条说,我试图从ecef转换为lla。



我正在使用此文档:转换文章直接公式中的
,而不是迭代公式
和此网站进行结果比较: ECEF2LLA



我在java中开发所以我的代码如下:

  public static final double a = 6378137; 
public static final double f = 1 / 298.257223563;
public static final double b = a *(1-f);
public static final double e = Math.sqrt((Math.pow(a,2)-Math.pow(b,2))/ Math.pow(a,2));
public static final double e2 = Math.sqrt((Math.pow(a,2)-Math.pow(b,2))/ Math.pow(b,2));
public static double [] ecef2lla(double x,double y,double z){
double [] lla = {0,0,0};
double lon,lat,height,N;
double p = Math.sqrt(Math.pow(x,2)+ Math.pow(y,2));
double theta = Math.atan((z * a)/(p * b));
lon = Math.atan(y / x);
lon = lon * 180 / Math.PI;

lat = Math.atan(((z + Math.pow(e2,2)* b * Math.pow(Math.sin(theta),3))/((p-Math。 pow(e,2)* a * Math.pow(Math.cos(theta),3)))));
lat =(lat * 180)/Math.PI;

N = a /(Math.sqrt(1-Math.pow(e * Math.sin(lat),2)));
height =(p / Math.cos(theta)) - N;
lla [0] = lon;
lla [1] = lat;
lla [2] =高度;
返回lla;

}

我收到错误的高度数据。
我已经尝试移动到弧度和度数,什么不是。



预先感谢您!

解决方案

好的,我得到了这个工作。



问题是一个错位的变量,所以为了我们的未来,工作JAVA实现:

  public static final double a = 6378137; 
public static final double f = 0.0034;
public static final double b = 6.3568e6;
public static final double e = Math.sqrt((Math.pow(a,2) - Math.pow(b,2))/ Math.pow(a,2));
public static final double e2 = Math.sqrt((Math.pow(a,2) - Math.pow(b,2))/ Math.pow(b,2));

public static double [] ecef2lla(double x,double y,double z){

double [] lla = {0,0,0};
double lan,lon,height,N,theta,p;

p = Math.sqrt(Math.pow(x,2)+ Math.pow(y,2));

theta = Math.atan((z * a)/(p * b));

lon = Math.atan(y / x);

lat = Math.atan(((z + Math.pow(e2,2)* b * Math.pow(Math.sin(theta),3))/((p - Math。 pow(e,2)* a * Math.pow(Math.cos(theta),3)))));
N = a /(Math.sqrt(1 - (Math.pow(e,2)* Math.pow(Math.sin(lat),2))));

double m =(p / Math.cos(lat));
height = m - N;


lon = lon * 180 / Math.PI;
lat = lat * 180 / Math.PI;
lla [0] = lat;
lla [1] = lon;
lla [2] =高度;
返回lla;

注意 ECEF XYZ 位于


Ive looked through the posts in the site and haven't found my problem ... as the head line says im trying to convert from ecef to lla .

I'm using this document : Conversion article in the direct formula , not the iterate formula and this site for result comparison : ECEF2LLA

Im developing in java so my code is as follows :

public static final double a = 6378137;
public static final double f = 1/298.257223563;
public static final double b = a*(1-f);
public static final double e = Math.sqrt((Math.pow(a, 2)-Math.pow(b, 2))/Math.pow(a, 2));
public static final double e2 = Math.sqrt((Math.pow(a, 2)-Math.pow(b, 2))/Math.pow(b, 2));
public static double[] ecef2lla(double x , double y , double z){
    double[] lla = {0,0,0};
    double lon,lat,height,N;
    double p = Math.sqrt(Math.pow(x, 2)+Math.pow(y, 2));
    double theta = Math.atan((z*a)/(p*b));
    lon = Math.atan(y/x);
    lon = lon*180/Math.PI;

    lat = Math.atan(((z+Math.pow(e2, 2)*b*Math.pow(Math.sin(theta), 3))/((p-Math.pow(e,2)*a*Math.pow(Math.cos(theta), 3)))));
    lat = (lat*180)/Math.PI;

    N= a/(Math.sqrt(1-Math.pow(e*Math.sin(lat), 2)));
    height = (p/Math.cos(theta)) - N;
    lla[0] = lon;
    lla[1] = lat;
    lla[2] = height;
    return lla;

}

I'm getting wrong height data. I've tried to move to radians and degrees and what not .

Thank you in advance !

解决方案

OK so i got this working.

The problem was a misplaced variable, so for the sake of our future here's the working JAVA implementation :

public static final double a = 6378137;
public static final double f = 0.0034;
public static final double b = 6.3568e6;
public static final double e = Math.sqrt((Math.pow(a, 2) - Math.pow(b, 2)) / Math.pow(a, 2));
public static final double e2 = Math.sqrt((Math.pow(a, 2) - Math.pow(b, 2)) / Math.pow(b, 2));

public static double[] ecef2lla(double x, double y, double z) {

    double[] lla = { 0, 0, 0 };
    double lan, lon, height, N , theta, p;

    p = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));

    theta = Math.atan((z * a) / (p * b));

    lon = Math.atan(y / x);

    lat = Math.atan(((z + Math.pow(e2, 2) * b * Math.pow(Math.sin(theta), 3)) / ((p - Math.pow(e, 2) * a * Math.pow(Math.cos(theta), 3)))));
    N = a / (Math.sqrt(1 - (Math.pow(e, 2) * Math.pow(Math.sin(lat), 2))));

    double m = (p / Math.cos(lat));
    height = m - N;


    lon = lon * 180 / Math.PI;
    lat = lat * 180 / Math.PI; 
    lla[0] = lat;
    lla[1] = lon;
    lla[2] = height;
    return lla;
}

Note : The units for the ECEF X Y Z are in Meters !

这篇关于在Java中ECEF到lla(lat,lon,alt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆