I am trying to fully understand the concept of Azimuth and I am encountering some inconsistencies (or maybe it is my error).
I show you some examples that do not match, hoping somebody can explain me how this really works.
/* Difference between the two longitudes */ var dLon = lon2 - lon1; /* Y value */ var y = Math.sin(dLon) * Math.cos(lat2); /* X value */ var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon); /* Calculates the azimuth between the two points and converts it to degrees */ var angle = Math.atan2(y, x) / Math.PI * 180;
/* Same Y, not on the equator */ Point A: (-81328.998084106, 7474929.8690234) Point B: (4125765.0381464, 7474929.8690234) Result in PostGIS: 90 degrees Result in my JS function: 74.232 degrees /* Same Y, on the equator */ Point A: (-81328.998084106, 0) Point B: (4125765.0381464, 0) Result in PostGIS: 90 degrees Result in my JS function: 90 degrees
I understand, that on the equator, the Azimuth is 90 (or 270) for a horizontal line. think that if you draw a horizontal line a bit North (or South) of the equator, then the Azimuth is not 90 degrees anymore. But... PostGIS tells me that it is always 90 degrees when we have the same Y.
Additionally, this calculator also show that the Azimuths of horizontal lines are not 90 degrees when Y != 0 (not on the equator).
How is it correct?