# from/to ellipsode to/from cartesian conversion

i am trying to convert from/to ellipsoidal coordinates (lat,lng,alt) to/from cartesian(x,y,z) i wrote the below code to do the conversion, but given the initial values of the gpsLat and gpsLng i receive certain value ofr the northing and Easting, but the problem is when I convert from Northing and Easting to get the Longitude i do not get the same longitude which is 8.427421853866282

the equation i am using i found it in

``````http://www.navipedia.net/index.php/Ellipsoidal_and_Cartesian_Coordinates_Conversion
``````

please let me know how to get the correct values

code

``````public static void main(String[] args) {
double semiMajorAxis = 149598023; //in km
double eccentricity = 0.0167086;
double Northing;
double Easting;
double computedLng;

double gpsLat = 49.01511835412477;
double gpsLng = 8.427421853866282;
double gpsAlt = 137.56704112819037;

radOfCurvature = semiMajorAxis/Math.sqrt(1 - ( (Math.pow(eccentricity,2) * Math.pow(Math.sin(gpsLat), 2)) ) );
Northing = (radOfCurvature + gpsAlt) * Math.cos(gpsLat) * Math.sin(gpsLng);
Easting = (radOfCurvature + gpsAlt) * Math.cos(gpsLat) * Math.cos(gpsLng);
computedLng = Math.atan(Northing/Easting);

System.out.println("Northing: " + Northing);
System.out.println("Easting: " + Easting);
System.out.println("computedLng: " + computedLng);
}
``````

result of the code

``````Northing: 3.9587600919687316E7
Easting: -2.5566975079396147E7
computedLng: -0.9973561069030983
``````