ProjectionWgs84 implements GeographicProjection { @Override public Vec3 geographicToCartesianNormal(Globe globe, double latitude, double longitude, Vec3 result) { if (globe == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ProjectionWgs84", "geographicToCartesianNormal", "missingGlobe")); } if (result == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "ProjectionWgs84", "geographicToCartesianNormal", "missingResult")); } double radLat = Math.toRadians(latitude); double radLon = Math.toRadians(longitude); double cosLat = Math.cos(radLat); double sinLat = Math.sin(radLat); double cosLon = Math.cos(radLon); double sinLon = Math.sin(radLon); double eqr2 = globe.getEquatorialRadius() * globe.getEquatorialRadius(); double pol2 = globe.getPolarRadius() * globe.getPolarRadius(); result.x = cosLat * sinLon / eqr2; result.y = (1 - globe.getEccentricitySquared()) * sinLat / pol2; result.z = cosLat * cosLon / eqr2; return result.normalize(); } ProjectionWgs84(); @Override String getDisplayName(); @Override Vec3 geographicToCartesian(Globe globe, double latitude, double longitude, double altitude, Vec3 result); @Override Vec3 geographicToCartesianNormal(Globe globe, double latitude, double longitude, Vec3 result); @Override Matrix4 geographicToCartesianTransform(Globe globe, double latitude, double longitude, double altitude, Matrix4 result); @Override float[] geographicToCartesianGrid(Globe globe, Sector sector, int numLat, int numLon, float[] height, float verticalExaggeration,
                                             Vec3 origin, float[] result, int offset, int rowStride); float[] geographicToCartesianBorder(Globe globe, Sector sector, int numLat, int numLon, float height,
                                               Vec3 origin, float[] result); @SuppressWarnings({"UnnecessaryLocalVariable", "SuspiciousNameCombination"}) @Override Position cartesianToGeographic(Globe globe, double x, double y, double z, Position result); @Override Matrix4 cartesianToLocalTransform(Globe globe, double x, double y, double z, Matrix4 result); @Override boolean intersect(Globe globe, Line line, Vec3 result);  }
@Test public void testGeographicToCartesianNormal() throws Exception { ProjectionWgs84 wgs84 = new ProjectionWgs84(); double lat = 34.2; double lon = -119.2; double latRad = Math.toRadians(lat); Vec3 result = wgs84.geographicToCartesianNormal(globe, lat, lon, new Vec3()); double theta = Math.toDegrees(Math.asin(result.y)); double lambda = Math.toDegrees(Math.atan2(result.x, result.z)); assertEquals("latitude: ", theta, lat, 1e-6); assertEquals("longitude: ", lambda, lon, 1e-6); }