Created
November 26, 2019 23:51
-
-
Save alekfrohlich/58a88b770397ed866981cf538a3cf494 to your computer and use it in GitHub Desktop.
LLA to ECEF convertion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.lang.Math.*; | |
public class Geo { | |
private static final double a = 6378137.0; // WGS-84 semi-major axis | |
private static final double e2 = 6.6943799901377997e-3; // WGS-84 first eccentricity squared | |
/** | |
* Convert Lat, Lon, Altitude to Earth-Centered-Earth-Fixed (ECEF). | |
* Input is a three element array containing lat, lon (deg) and alt (m). | |
* Returned array contains x, y, z in meters. | |
*/ | |
public static double[] geo_to_ecef(double[] geo) { | |
double[] ecef = new double[3]; | |
double lat = geo[0]* Math.PI / 180; | |
double lon = geo[1]* Math.PI / 180; | |
double alt = geo[2]; | |
double n = a / sqrt(1 - e2*sin(lat) * sin(lat)); | |
ecef[0] = (n + alt) * cos(lat) * cos(lon); // ECEF x | |
ecef[1] = (n + alt) * cos(lat) * sin(lon); // ECEF y | |
ecef[2] = (n*(1 - e2) + alt) * sin(lat); // ECEF z | |
return ecef; | |
} | |
public static void main(String[] args) { | |
double[] c = {34.127713, -117.825459, 250.64}; | |
for (double d : Coord.geo_to_ecef(c)) | |
System.out.println(d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment