# Is the Azimuth on the equator equal to the one not on the equator?

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.

I show the coordinates in EPSG:900913, in PostGIS and using my own JavaScript function.

MY FUNCTION

``````/* 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;
``````

EXAMPLES

``````/* 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?

Thanks

• Your readers cannot tell you about your JS function because you do not supply it. For the reason why azimuths are not 90 degrees between points at the same nonzero latitudes, please see gis.stackexchange.com/questions/6822. – whuber Aug 27 '14 at 14:43
• The first question for me is "what Azimuth do you want". Azimuth is defined based on a reference plane and a sphere. The sphere can be the Earth or a celestial sphere. So you need to know what you are looking for before writing your code. – radouxju Aug 27 '14 at 19:21
• @radouxju An azimuth can be uniquely defined at all points on any surface of revolution except its poles, if any: that includes the sphere and all ellipsoids. It is given by the oriented angle between a direction and the direction of the meridian at that point. I believe this question is asking for the bearings ("azimuths") of geodesics on ellipsoids. More about this appears after the edit to my answer at gis.stackexchange.com/a/6824. As far as I can tell, that answer fully addresses this question; I do not know why this question was reopened. – whuber Aug 27 '14 at 20:06
• the calculator mentioned by the OP seems to compute the azimuth angle of a satellite from a given location, hence my question. But maybe this is the same if you project the satellite on the Earth ellipsoid. Thanks for your post, by the way, great answer. – radouxju Aug 27 '14 at 20:26
• Thank you for your contributions, @whuber and radouxju. I want the Azimuth on Earth, i.e. the angle between two locations. I am testing some azimuth calculations with my JS function (shown in the post), and for the points A(-170, -89) to B(10, 89), but I get many different solution, thus not knowing which one is the correct. Would you please take a look at this question I just asked? Thank you. – joaorodr84 Aug 28 '14 at 16:06

On the surface of a sphere, all lines are "horizontal lines" by definition. But you mean something else!

If you refer to lines parallel to the equator (parallels of latitude), then they are all oriented E-W, i.e., have 0 or 270 azimuths. Any line, including those parallels, whose azimuth is unchanged at all points along it, is called a loxodrome (or rhumb line).

If you refer, however, to the azimuth of the shortest line between any two points on the surface of a sphere, such lines are called great circles (or geodesics or orthodromes) and, generally, the azimuth varies as you travel along it. (from wiki)

The equator is both an orthodrome and a loxodrome. So too are the meridians. Parallels of latitude, however, are only loxodromes. The orthodrome connecting any two points of equal latitude veers away from and then back towards the parallel of lattitude. How far away it veers depends on how large is the latitude (away from the equator) and how far apart are the points.

If PostGIS got it wrong, you probably didn't tell `ST_Azimuth()` to use geographic coordinates.