<p>You miss the simple fact that a circle is 360° periodic. Your result is correct:</p>
<p>360°-14.66° = 345.34°.</p>
<p>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.</p>

CC BY-SA 4.0
2020-06-23T10:43:49.277Z
2020-06-23T10:43:49.277Z
planetmaker
<p>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°.</p>

CC BY-SA 4.0
2020-06-23T14:33:07.120Z
@skiventist `atan2` is almost always a better choice than plain `atan`. And it properly handles the case when `x=0`.
PM 2Ring
CC BY-SA 4.0
2020-06-23T10:49:11.950Z
2020-06-23T10:49:11.950Z
David Hammen
<p>I'm following the steps in <a href="https://arxiv.org/pdf/0910.2778.pdf" rel="nofollow noreferrer">this</a> paper on how to calculate geocentric longitude. In section 3.4.2 it says the</p>
<p>Geocentric rectangular co-ordinates of Mercury then are:</p>
<pre><code>Xg = Xh−X0 = 0.990 A.U.
Yg = Yh−Y0 = −0.259 A.U.
</code></pre>
<p>Converting these into polar form, we get the geocentric distance and longitude as:</p>
<pre><code>rg = √(X2g+Y2g) = 1.024 A.U.
λg = tan−1(Yg/Xg) = 345.3◦.
</code></pre>
<p>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:</p>
<pre><code>Xg= 0.990 
Yg= -0.259 
math.degrees(math.atan(Yg/Xg)) = -14.66091789971255
</code></pre>
<p>Any help greatly appreciated.</p>

<positional-astronomy>
Converting rectangular to polar coordinates
skiventist
# Converting rectangular to polar coordinates

(Asked by: username_0 on 2020-06-23)

I'm following the steps in [this](https://arxiv.org/pdf/0910.2778.pdf) 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.

**Tags:** positional-astronomy


---

## 2 answers

### Answer by username_1 on 2020-06-23. Score: 3 | Accepted answer

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.


---

### Answer by username_2 on 2020-06-23. Score: 3

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°.

> **Comments:**
> **username_3**: @username_0 `atan2` is almost always a better choice than plain `atan`. And it properly handles the case when `x=0`.  

---

