[英]Function that converts GPS coordinates to ENU coordinates?
我想將gps坐標(緯度,經度)轉換為ENU(est,north,up)坐標。
我知道關於這個問題的理論,但我沒有時間實現它所以我問是否存在java代碼來做到這一點!
謝謝
只是Java中的一個簡單實現,可將GPS坐標轉換為ENU坐標。
public List<Double> convertGpsToECEF(double lat, double longi, float alt) {
double a=6378.1;
double b=6356.8;
double N;
double e= 1-(Math.pow(b, 2)/Math.pow(a, 2));
N= a/(Math.sqrt(1.0-(e*Math.pow(Math.sin(Math.toRadians(lat)), 2))));
double cosLatRad=Math.cos(Math.toRadians(lat));
double cosLongiRad=Math.cos(Math.toRadians(longi));
double sinLatRad=Math.sin(Math.toRadians(lat));
double sinLongiRad=Math.sin(Math.toRadians(longi));
double x =(N+0.001*alt)*cosLatRad*cosLongiRad;
double y =(N+0.001*alt)*cosLatRad*sinLongiRad;
double z =((Math.pow(b, 2)/Math.pow(a, 2))*N+0.001*alt)*sinLatRad;
List<Double> ecef= new ArrayList<>();
ecef.add(x);
ecef.add(y);
ecef.add(z);
return ecef;
}
public List<Double> convertECEFtoENU(List<Double> ecefUser, List<Double> ecefPOI, double lat, double longi){
double cosLatRad=Math.cos(Math.toRadians(lat));
double cosLongiRad=Math.cos(Math.toRadians(longi));
double sinLatRad=Math.sin(Math.toRadians(lat));
double sinLongiRad=Math.sin(Math.toRadians(longi));
List<Double> vector = new ArrayList<>();
vector.add(ecefUser.get(0)-ecefPOI.get(0));
vector.add(ecefUser.get(1)-ecefPOI.get(1));
vector.add(ecefUser.get(2)-ecefPOI.get(2));
double e= vector.get(0)*(-sinLongiRad)+vector.get(0)*(cosLongiRad);
double n= vector.get(0)*(-sinLatRad)*(cosLongiRad)+vector.get(1)*(-sinLatRad)*(sinLongiRad)+vector.get(2)*cosLatRad;
double u= vector.get(0)*(cosLatRad)*(cosLongiRad)+vector.get(1)*(cosLatRad)*(sinLongiRad)+vector.get(2)*sinLatRad;
List<Double> enu= new ArrayList<>();
enu.add(e);
enu.add(n);
enu.add(u);
return enu;
}
/**
* @param origin
* @return Local (ENU) coordinates
*/
public void computeLocal(Coordinates target) {
if(this.geod==null) computeGeodetic();
SimpleMatrix R = rotationMatrix(this);
enu = R.mult(target.minusXYZ(this));
}
另請參見TopocentricCoordinates.java
public void computeTopocentric(Coordinates origin, Coordinates target) {
origin.computeLocal(target);
double E = origin.getE();//enu.get(0);
double N = origin.getN();//enu.get(1);
double U = origin.getU();//enu.get(2);
其他解決方案是:
public static double[] fatCoordinates(double lat,double lon){
double phi = Math.toRadians(lat);
double lambda = Math.toRadians(lon);
double e2 = Math.pow(WGS_E,2);
double Rn = WGS_A / Math.sqrt(1 - e2 * Math.pow(Math.sin(phi), 2));
double[] XYZ = new double[3];
XYZ[0] = Rn * Math.cos(phi) * Math.cos(lambda);
XYZ[1] = Rn * Math.cos(phi) * Math.sin(lambda);
XYZ[2] = Rn * (1 - e2) * Math.sin(phi);
return XYZ;
}
同
public static final double WGS_A = 6378137.0;
public static final double WGS_E = 0.0818191908426;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.