Position pos = this.cartesianToGeographic(globe, x, y, z, this.scratchPos); double radLat = Math.toRadians(pos.latitude); double radLon = Math.toRadians(pos.longitude);
/** * Tests the geodetic coordinates against values defined in the NIMA WGS specifications: * http://earth-info.nga.mil/GandG/publications/tr8350.2/Addendum%20NIMA%20TR8350.2.pdf * * @throws Exception */ @Test public void testCartesianToGeographic() throws Exception { ProjectionWgs84 wgs84 = new ProjectionWgs84(); Map<String, Object[]> stations = getStations(); for (Map.Entry<String, Object[]> station : stations.entrySet()) { Position p = (Position) station.getValue()[0]; Vec3 v = (Vec3) station.getValue()[1]; Position result = new Position(); // Note: we must rotate the axis to match the WW coord system to the WGS ECEF coord system // WW: Y is polar axis, X and Z line on the equatorial plane with X coincident with +/-90 and Z +/-180 wgs84.cartesianToGeographic(globe, v.x, v.y, v.z, result); assertEquals(station.getKey(), Location.normalizeLatitude(p.latitude), result.latitude, 1e-6); assertEquals(station.getKey(), Location.normalizeLongitude(p.longitude), result.longitude, 1e-6); assertEquals(station.getKey(), p.altitude, result.altitude, 1e-3); } }
/** * Simply tests that the reciprocal method will regenerate the original value. * * @throws Exception */ @Test public void testCartesianToGeographic_Reciprocal() throws Exception { ProjectionWgs84 wgs84 = new ProjectionWgs84(); double x = -4610466.9131683465; // KOXR airport double y = 3565379.0227454384; double z = -2576702.8642047923; Vec3 vec = new Vec3(); Position pos = new Position(); wgs84.cartesianToGeographic(globe, x, y, z, pos); wgs84.geographicToCartesian(globe, pos.latitude, pos.longitude, pos.altitude, vec); assertEquals("x", x, vec.x, 1e-6); assertEquals("y", y, vec.y, 1e-6); assertEquals("z", z, vec.z, 1e-6); }
/** * Simply tests that the reciprocal method will regenerate the original value. * * @throws Exception */ @Test public void testGeographicToCartesian_Reciprocal() throws Exception { ProjectionWgs84 wgs84 = new ProjectionWgs84(); double lat = 34.2; // KOXR airport double lon = -119.2; double alt = 1000; Vec3 vec = new Vec3(); Position pos = new Position(); wgs84.geographicToCartesian(globe, lat, lon, alt, vec); wgs84.cartesianToGeographic(globe, vec.x, vec.y, vec.z, pos); assertEquals("lat", lat, pos.latitude, 1e-6); assertEquals("lon", lon, pos.longitude, 1e-6); assertEquals("alt", alt, pos.altitude, 1e-6); }