# NavList:

## A Community Devoted to the Preservation and Practice of Celestial Navigation and Other Methods of Traditional Wayfinding

**Re: POL and arctan2**

**From:**George Huxtable

**Date:**2005 Nov 4, 12:05 -0000

----- Original Message ----- From: "Bill"To: Sent: Thursday, November 03, 2005 1:39 AM Subject: [NAV-L] POL and arctan2 > Thanks to George et al for working me through the similarities/differences > of two tangent-based azimuth formulas. > > That, and the methods HO229 use to create the tables being digested, > George's post offered another calculator method of determining azimuth > that > has stayed under the list radar. > > George wrote: > > "If a calculator or computer offers a POL or arctan2 function then you > don't > even need to apply those rules; the azimuth comes out straightaway in its > correct quadrant, from 0 to 360. > > For example, the correct angle results from applying- > > POL((tan dec cos lat - cos (hour angle)sin lat, -sin (hour angle)). > > Before applying this formula, however, check whether the term before the > comma and the term after the comma do not both happen to be zero. If they > do, the angle is indeterminate, and an error may result." > > George > > These terms are new to me. I wonder if they might be the same as or > similar > to the rectangular-to-polar and polar-to-rectangular functions on my > TI-30XA? With the TI-30XA, I enter two figures and get two back. Presumably yes, though I'm unfamiliar with TI calculators. > > With those functions I can convert difference in Lat 1 and Lat 2, and Lon > 1 > and Lon 2 to miles, and properly signed, it will give me course and > distance > for short trips (under 300 nm) plenty good enough for a sailing vessel. As > you stated, no rules need to be applied to the course value--unless it is > negative, then add 360. The only trick is to enter latitude as the x > value > and longitude as the y value to account for the differences in cardinal > vs. > trig coordinate systems. Also can enter course and distance and calculate > Lat and Lon differences from departure point. Yes; the "properly signed" part is important. And for short distances, such a flat-Earth approximation is good enough. > > If POL and arctan2 are the same as my P to R and R to P functions, would > you please go into a bit more detail on how to use them with your method? > I > am also confused by the "," after sin lat in your formula. What you are doing when you use the POL function and the arctan2 (which is usually stated as atan2 or atn2) is to enter two quantities, and that comma separates them. Before the comma is the y-value, or northing, and after it is the x-value, or Easting, both in miles, of the destination from the departure point. That's similar to what you are doing with your TI calculator. The old HP21 calculator (mine still works, after 30 years!) does something similar , using a button marked with a right-arrow and P. In each case, what you do is to put Northing and Easting into the x and y registers, and the contents of those registers get replaced with the distance d and the angle A. What they are doing is converting from rectangular to polar coordinates. The conventional way of representing this is best shown if you draw a little diagram. From an origin point draw a horizontal line to the right, and mark that the x axis. Mark on it a point 3 units (inches, say) from the origin and draw a line upwards from it. Draw another line vertically upward from the origin (that's the y axis) mark a point 1 inch up from the origin, and draw a line to the right.. The two lines cross at a point (x = 3, y = 1), which we can name P. What I've described above is called "Cartesian coordinates", named after the French philosopher Descartes. Anyone who has drawn a graph will be familiar with Cartesian coordinates. Now draw a straight line between that point (3,1) and the origin. The length of that line (by Pythagoras) is the square root of (x squared + y squared). Call that R, which equals 3.162 inches in this case. And the angle A (often named "theta", but A is easier in ASCII text) is arctan (y/x), from the definition of a tangent). So A = arctan (1/3), or 18.4 degrees, measured anticlockwise from the x axis. R and A are the polar coordinates of the point, in distance and angle from the origin, of which the rectangular coordinates were x and y. They are just two different ways of defining the positions of points in a plane. Most scientific calculators and computing programs have a way to make it easy to convert from one to the other. There's a snag, though. X and Y can each take negative values, on the opposite side of the origin.Compare our point P, at (3,1) rectangular, or (3.162, 18.4 deg) polar, with another point exactly opposite across the origin, at x=-3, y=-1. Now our polar conversion, if it worked exactly as described above, would calculate the correct value for R, for that new point. However, if it relied on calculating A from arctan (y/x), it would get exactly the same result, 18.4 deg, as before, because (y/x) is exactly the same when y=1, x=3, as when y=-1, x=-3. That's the same as saying that the tan of an angle repeats twice as you go right round a circle, and if you add 180 degrees to an angle its tan is unaltered. So, just knowing the tan, you can't be sure which of two possible angles is returned by arctan (y/x). A calculator or computer will return an angle between -90 deg, through zero, to +90 deg. If the angle is between +90, through 180, to +270 (same as -90), there's no way of telling, just knowing its tan. The polar conversion is clever enough, not just to divide x by y to get arctan (y/x), but to note the signs of x and y, and to put the angle A into the right quadrant (0 to 360 measured anticlockwise from the x axis) accordingly. It's written arctan2 (x,y) or POL (x,y) Sorry about all that excruciating detail, which I'm sure is quite unnecessary for most readers. It's for the others. Well, that's the "conventional" way to measure the angle A, and it's what all the polar conversion functions do. But you can see that the conventional angle A differs greatly from the azimuth that we use for bearings at sea, which is measured clockwise from North, not anticlockwise from East. We can put that right by interchanging the x and y coordinates, so that the expression for the true azimuth becomes arctan (x/y) or, to get it into the range 0 to 360 deg, arctan2 (y,x) or POL (y,x). That's probably what Bill's polar function on his TI gives him if he enters Northing and Easting for his flat-Earth calculation. Now lets see how all that affects the round-Earth spherical-trig formula for azimuth which we discussed earlier. It applies to any observation, or great-circle track, around the Earth, not just for short distances like the formula Bill has used, and it would be exact if the Earth was a perfect sphere (which it isn't, quite, but near enough for our purposes). We adapt it from Meeus, equation 13.5, which gives- az = arctan ( sin LHA / (cos LHA sin lat - tan dec cos lat)) Lat and dec are both positive North, negative South, and LHA is measured Westwards from the observer. Compare it with our earlier expression arctan(x/y), and note the similarity. However, LHA is now measured in the opposite direction to x, which was conventionally Eastward. That changes the sign of sin LHA, but not of cos LHA. Also, Meeus uses an astronomers' convention of measuring his azimuths clockwise from South, not from North as navigators do. To allow for those, we reverse the sign of the numerator, from sin LHA to -sin LHA, and also the denominator, from (cos LHA sin lat - tan dec cos lat) to ( tan dec cos lat -cos LHA sin lat ) so now, to get azimuth in the range 0 to 360, we can write, just like we did for atan2(y , x), the final formula for az, as- az = arctan2 ( tan dec cos lat - cos LHA sin lat , - sin LHA) Really, you don't need to know any of the stuff above, except for that final formula for az. But Bill asked... It will give a true result, for all azimuths, even when the body is actually out of sight around the curve of the Earth, below the horizon, with a negative altitude. Bill can also use an equivalent expression for great-circle course (0 to 360) to any destination, no matter how far away, from a point (lat 1, long 1) to (lat 2, long 2), where the longitudes are measured Westerly (i.e. East is negative). Some navigators, texts, and programs measure longitudes the opposite way, but to me, it's illogical to measure LHA one way, and longitude the other.. He will need dlong, which is long 2 - long 1 course = ATAN2 (or POL, as appropriate) ( tan lat 2 cos lat 1 - cos dlong sin lat 1 , -sin dlong) If Bill does that , using the equivalent function on his TI calculator whatever that is, he will no longer have to calculate departure, in miles, from the change in long, as was necessary before. Of course, most computer programs work in radians rather that degrees, in which case some conversions will be required. One tripup that may need looking out for is when lat 2 = lat 1 and long 2 = long 1, looking for a course to the same spot as the observer. Another is when lat 2 = -lat 1 and long 2 = - long 1, looking for a course to the antipode. In either case, the result is indeterminate, and the computer may stop with an error, depending on its level of sophistication. I do hope there are no silly errors in the text above. If there are, no doubt some kind soul will pick them up. George.