3

First of all, let's make clear that I want the Azimuth on the surface of the Earth, i.e. the angle between two locations, for example New York and Moscow.

I am testing some azimuth calculations with my JS functions (shown below). For the points A(-170, -89) to B(10, 89), I get ~90º.

JS function for Azimuth on sphere (from Wikipedia)

var dLon = lon2 - lon1;
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
var angle = Math.atan2(y, x) * 180 / Math.PI;

JS function for Azimuth on oblate spheroid (from Wikipedia)

var dLon = lon2 - lon1;
var f = 1 / 298.257223563;    /* Flattening for WGS 84 */
var b = (1 - f) * (1 - f);
var tanLat2 = Math.tan(lat2);
var y = Math.sin(dLon);
var x;
if (lat1 === 0) {
    var x = b * tanLat2;
} else {
    var a = f * (2 - f);
    var tanLat1 = Math.tan(lat1);
    var c = 1 + b * tanLat2 * tanLat2;
    var d = 1 + b * tanLat1 * tanLat1;
    var t = b * Math.tan(lat2) / Math.tan(lat1) + a * Math.sqrt(c / d);
    var x = (t - Math.cos(dLon)) * Math.sin(lat1);
}
var angle = Math.atan2(y, x) * 180 / Math.PI;

In Calculator 2, I get 90º.

In PostGIS, I get 270º

In Calculator 1, I get 180º.

I know the Azimuth gets more and more distorted near the Poles, but that's exactly why I am testing at these spots. This variety of different solutions are confusing me. Could you please help me getting the right answer for this?

6
  • 1
    There's also this calculator which uses the Vincenty method for solving geodesy's "inverse" problem. It gives what I would expect for the azimuth: zero.
    – mkennedy
    Commented Aug 28, 2014 at 17:43
  • 2
    Sorry, I misread the first latitude value! The NGS calculator referred to in the earlier comment is hanging, but Esri's implementation (also Vincenty with a few tweaks) returns 0. I'm using GRS80 rather than a sphere. Both 0 and 180.0 are valid. One goes N over N Pole, other goes S over S Pole; same distance.
    – mkennedy
    Commented Aug 28, 2014 at 20:40
  • 1
    looks like a disagreement over where 0 is - check the docs. I've seen noon, 3pm and 6pm all used.
    – Ian Turton
    Commented Aug 29, 2014 at 7:28
  • 1
    Indeed, many solutions are valid, but if you consider the oblate spheroid, North and South are the correct solutions. Thank you! :)
    – joaorodr84
    Commented Aug 29, 2014 at 11:28
  • 1
    Hi, also wanted to point out geographiclib.sourceforge.net . A library with beautiful sets of functions to help you calculate everything related to geography
    – nickves
    Commented Aug 30, 2014 at 22:53

3 Answers 3

2

First, be careful with phrasing. Your "the angle between two locations" is unclear.

Keeping things to a simple sphere, the azimuth of any oblique great circle route depends entirely on where you measure it. It can range all the way from 0 to 360 and be correct. You probably seek the starting azimuth of a great circle route from a certain point to another point.

Your test points are at strange locations (but it's good to test those situations): they're exactly opposite one another across the globe's diameter -- they're antipodal points -- and they're near the poles. There are always an infinity of possible great circle routes from any one point to its antipodal point!

The azimuth of any oblique great circle route at its most northern and most southern points will always be exactly 90 or 270, depending only on your preferred direction of travel.

The general trend of the great circle of your test example is approximately 0 and 180, once you're well away from the poles. It would be instructive to use an example of New York to London or Moscow, and vice versa, and see any differences.

0
1

In addition to an answer over in SO, the inverse geodetic solution is not easy with near-antipodal points, as your question has. The inverse geodetic problem is solved iteratively using Vincenty's 1975 algorithm, which fails to converge for near antipodal points. However, the problem is still solvable using a different approach.

See page 40 of Rapp RH (1993) for the geodesic behaviour of near antipodal points.

Also, see Karney (2013) for general purpose algorithms for geodesics, which are implemented in GeographicLib, and handle near-antipodal cases.

1
  • I'll be sure to check out these links. Thank you very much! :)
    – joaorodr84
    Commented Sep 2, 2014 at 1:42
0

Recommend using software developed by Karney. https://geographiclib.sourceforge.io/cgi-bin/GeodSolve Enter Lat1=-89, Lon1=-170, Lat2=89, Lon2=10 click on Inverse button and then click on SUBMIT: the answer is 180 at point 1 and 0 at point 2, with geodesic distance between points 1 and 2 s12 = 20,003,931.459 meters. Points 1 and 2 are perfectly antipodal and reside on the “meridional” geodesic running from N Pole to S Pole and back to N pole on the opposite side of the globe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.