/** * Tests the cartesian 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 testGeographicToCartesian() 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]; Vec3 result = new Vec3(); wgs84.geographicToCartesian(globe, p.latitude, p.longitude, p.altitude, result); // Note: we must rotate the axis to match the WW coord system to the WGS coord system // WW: Y is polar axis, X and Z line on the equatorial plane with X +/-90 and Z +/-180 // WGS: Z is polar axis assertEquals(station.getKey(), v.x, result.x, 1e-3); assertEquals(station.getKey(), v.y, result.y, 1e-3); assertEquals(station.getKey(), v.z, result.z, 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); }