# Converting rectangular to polar coordinates

I'm following the steps in this paper on how to calculate geocentric longitude. In section 3.4.2 it says the

Geocentric rectangular co-ordinates of Mercury then are:

Xg = Xh−X0 = 0.990 A.U.
Yg = Yh−Y0 = −0.259 A.U.


Converting these into polar form, we get the geocentric distance and longitude as:

rg = √(X2g+Y2g) = 1.024 A.U.
λg = tan−1(Yg/Xg) = 345.3◦.


For the life of me I cannot get the inverse tan of (Yg/Xg) to give me 345.3. This is what I'm doing in python:

Xg= 0.990
Yg= -0.259
math.degrees(math.atan(Yg/Xg)) = -14.66091789971255


Any help greatly appreciated.

You miss the simple fact that a circle is 360° periodic. Your result is correct:

360°-14.66° = 345.34°.

Thus you miss that the arctan usually returns -180...+180° and you don't correct for the fact that the longitude is positive defined in the range of 0 ... 360°. Thus add +360° when your result is negative.

You should be using the two argument version of arctan, math.atan2(y, x), to ensure that the result is in the correct quadrant. But in this case math.atan2(y, x) will return the same value as math.atan(y/x). -14.66° is the equivalent to 345.34°.

• Noted thank you! Jun 23, 2020 at 10:52
• @skiventist atan2 is almost always a better choice than plain atan. And it properly handles the case when x=0. Jun 23, 2020 at 14:33