Azimuth { public static final double find(double lat1, double lon1, double lat2, double lon2) { double lat1Rad = Math.toRadians(lat1); double lat2Rad = Math.toRadians(lat2); double diffLonRad = Math.toRadians(lon2 - lon1); double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(diffLonRad); double y = Math.sin(diffLonRad) * Math.cos(lat2Rad); double azimuth = Math.atan2(y, x); if (azimuth < 0) { return azimuth + RADIANS_ADJUST; } else { return azimuth; } }  static final double find(double lat1, double lon1, double lat2, double lon2); static final double find(LatLonPoint point1, LatLonPoint point2); static final double find(Point point1, Point point2); static final double find(Coordinate coord1, Coordinate coord2);  }
@Test public void testFind_East() { double lat1 = 0.0; double lon1 = 0.0; double lat2 = 0.0; double lon2 = 10.0; double expResult = Math.toRadians(90); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }
@Test public void testFind_North() { double lat1 = 0.0; double lon1 = 0.0; double lat2 = 10.0; double lon2 = 0.0; double expResult = Math.toRadians(0); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }
@Test public void testFind_South() { double lat1 = 0.0; double lon1 = 0.0; double lat2 = -10.0; double lon2 = 0.0; double expResult = Math.toRadians(180); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }
@Test public void testFind_West() { double lat1 = 0.0; double lon1 = 0.0; double lat2 = 0.0; double lon2 = -10.0; double expResult = Math.toRadians(270); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }
@Test public void testFind_East_cross_boundary() { double lat1 = 0.0; double lon1 = 170.0; double lat2 = 0.0; double lon2 = -170.0; double expResult = Math.toRadians(90); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }
@Test public void testFind_West_cross_boundary() { double lat1 = 0.0; double lon1 = -170.0; double lat2 = 0.0; double lon2 = 170.0; double expResult = Math.toRadians(270); double result = Azimuth.find(lat1, lon1, lat2, lon2); assertEquals(expResult, result, 0.0); }