地心坐标系(ECEF)和WGS-84坐标系(WGS84)互转的实

2024-04-23  本文已影响0人  小辛_43ae

几个地理工具网站

经纬度换算:https://www.bejson.com/convert/map/
经纬度定位: https://www.earthol.com/g/
ECEF坐标系转换经纬度 wgs84:http://www.ab126.com/Geography/4031.html
由GEO的两行轨道根数TLE能否推算出卫星的定点经度?https://www.zhihu.com/question/24137989

地心坐标系(ECEF)和WGS-84坐标系(WGS84)互转的实现

public static String WGS84toECEF(double latitude, double longitude, double height)
  {
    double X;
    double Y;
    double Z;
    double a = 6378137;
    double b = 6356752.314245;
    double E = (a * a - b * b) / (a * a);
    double COSLAT = Math.cos(latitude * Math.PI / 180);
    double SINLAT = Math.sin(latitude * Math.PI / 180);
    double COSLONG = Math.cos(longitude * Math.PI / 180);
    double SINLONG = Math.sin(longitude * Math.PI / 180);
    double N = a / (Math.sqrt(1 - E * SINLAT * SINLAT));
    double NH = N + height;
    X = NH * COSLAT * COSLONG;
    Y = NH * COSLAT * SINLONG;
    Z = (b * b * N / (a * a) + height) * SINLAT;
    return X + "," + Y + "," + Z;
  }
 
 
  public static String ECEFtoWGS84(double x, double y, double z)
 
  {
    double a, b, c, d;
    double Longitude;//经度
    double Latitude;//纬度
    double Altitude;//海拔高度
    double p, q;
    double N;
    a = 6378137.0;
    b = 6356752.31424518;
    c = Math.sqrt(((a * a) - (b * b)) / (a * a));
    d = Math.sqrt(((a * a) - (b * b)) / (b * b));
    p = Math.sqrt((x * x) + (y * y));
    q = Math.atan2((z * a), (p * b));
    Longitude = Math.atan2(y, x);
    Latitude = Math.atan2((z + (d * d) * b * Math.pow(Math.sin(q), 3)), (p - (c * c) * a * Math.pow(Math.cos(q), 3)));
    N = a / Math.sqrt(1 - ((c * c) * Math.pow(Math.sin(Latitude), 2)));
    Altitude = (p / Math.cos(Latitude)) - N;
    Longitude = Longitude * 180.0 / Math.PI;
    Latitude = Latitude * 180.0 / Math.PI;
    return Longitude + "," + Latitude + "," + Altitude;
  }
上一篇下一篇

猜你喜欢

热点阅读