/** * Normalizes a longitude to be in the range [-π,π) radians. * * <p>Warning: This method produces a near-infinite loop if argument is a very large value.</p> */ public static final double normalizeLon( double lonRad ) { return normalizeAnglePi( lonRad ); }
/** * Normalizes a latitude to be in the range [-π/2,π/2] radians. * * <p>Warning: This method produces a near-infinite loop if argument is a very large value.</p> */ public static final double normalizeLat( double latRad ) { double angle = normalizeAnglePi( latRad ); if ( angle < -piOverTwo ) { angle = -pi - angle; } else if ( angle > piOverTwo ) { angle = pi - angle; } return angle; }
/** * Computes the great circle distance between the specified points using the * Haversine formula. */ public static double greatCircleDistance( double fromLat, double fromLon, double toLat, double toLon, double radius ) { double dLat = fromLat - toLat; double dLon = LatLonGeo.normalizeAnglePi( fromLon - toLon ); double c1 = Math.cos( fromLat ); double c2 = Math.cos( toLat ); double s1 = Math.sin( 0.5d * dLat ); double s2 = Math.sin( 0.5d * dLon ); // guard against roundoff-related problems double sinA = Math.sqrt( s1 * s1 + c1 * c2 * s2 * s2 ); if ( sinA > 1d ) { sinA = 1d; } return 2d * radius * Math.asin( sinA ); }
/** * Computes the great circle distance between the specified points using the * Haversine formula. */ public static double greatCircleDistance( double fromLat, double fromLon, double toLat, double toLon, double radius ) { double dLat = fromLat - toLat; double dLon = LatLonGeo.normalizeAnglePi( fromLon - toLon ); double c1 = Math.cos( fromLat ); double c2 = Math.cos( toLat ); double s1 = Math.sin( 0.5d * dLat ); double s2 = Math.sin( 0.5d * dLon ); // guard against roundoff-related problems double sinA = Math.sqrt( s1 * s1 + c1 * c2 * s2 * s2 ); if ( sinA > 1d ) { sinA = 1d; } return 2d * radius * fastAsin.evaluate( sinA ); } }