/** * This computes the initial heading (heading at the start point) of the segment on the surface * of earth between two locations * * @see "http://www.movable-type.co.uk/scripts/latlong.html" * @param that * The other point to compute the heading to * @return The heading between two points */ public Heading headingTo(final Location that) { if (this.equals(that)) { throw new CoreException("Cannot compute some heading when two points are the same."); } // convert to radians final double lat1 = this.getLatitude().asRadians(); final double lon1 = this.getLongitude().asRadians(); final double lat2 = that.getLatitude().asRadians(); final double lon2 = that.getLongitude().asRadians(); final double deltaLon = lon2 - lon1; final double yAxis = Math.sin(deltaLon) * Math.cos(lat2); final double xAxis = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(deltaLon); return Heading.radians(Math.atan2(yAxis, xAxis)); }