<p><em>Convert commments to community wiki</em></p>

<p>This is a standard problem with using an arctan function (inverse tan function returns a value between -90 and +90). A lot of programming languages have two functions the simple one like you appear to have used and a more complex one that takes two parameters for when you are dividing (before the arctan function) as in this case. (This is described in further detail at (<a href="http://youtu.be/_JbkTK17MrY" rel="nofollow noreferrer">http://youtu.be/_JbkTK17MrY</a>)</p>

<p>In Java you can use <code>α=atan2((cos ε∗sin λ−sin ε∗tan β), cos λ)</code> you may need to add 360 if the angle returned is negative.</p>

<p>An alternative is <code>α=atan2(cosβsinλcosε−sinβsinε,cosβcosλ)</code>. This is equivalent in most cases but avoids an infinite term <code>tanβtan⁡β</code> at the ecliptic poles, costing one more trig function call. </p>

CC BY-SA 4.0
2022-07-16T21:21:19.127Z
Just wanted to say thank you for that last paragraph. I've been trying to implement the algorithms from Astronomical Algorithms, and I realized that the `tan(β)` term was a ticking timebomb.
Edward Falk
CC BY-SA 3.0
2017-01-11T19:16:14.223Z
2017-01-11T19:16:14.223Z
James K
<p>When looking for a formula to convert polar ecliptic geocentric coordinates of an object to equatorial coordinates I find various sources that give these formulae (like <a href="https://en.wikipedia.org/wiki/Celestial_coordinate_system#Equatorial_.E2.86.90.E2.86.92_ecliptic" rel="nofollow">Wikipedia</a>):</p>

<p>Declination $δ = \arcsin(\cos ε \times \sin β + \sin ε \times \cos β \times \sin λ)$<br>
Right ascension $α = \arctan((\cos ε \times \sin λ - \sin ε \times \tan β) / \cos λ)$</p>

<p>Where<br>
β = ecliptic geocentric latitude<br>
λ = ecliptic geocentric longitude<br>
ε = obliquity of the ecliptic</p>

<p>But when applying these formulae I get results like in the following list where β = 0° and ε = 23.4°:</p>

<pre><code> λ       δ        α
  0   0.0000   0.0000
 45  16.3095  42.5443
 90  23.4000  90.0000
135  16.3095 -42.5443
180   0.0000  -0.0000
225 -16.3095  42.5443
270 -23.4000  90.0000
315 -16.3095 -42.5443
360  -0.0000  -0.0000
</code></pre>

<p>The values for declination seem good, but right ascension values seem to lack some sort of adjustment to the quadrant of the full circle (just a guess). But nowhere did I find any mentioning of this. Can you help? Thanks.</p>

CC BY-SA 3.0
2016-05-26T10:54:58.193Z
This is a standard problem with using an arctan function and the reason that a lot of programming languages have two functions the simple one like you appear to have used and a more complex one that takes two parameters for when you are dividing (before the arctan function) as in this case. Here is a video describing the issue (https://youtu.be/_JbkTK17MrY).
James Screech
CC BY-SA 3.0
2016-05-26T10:55:54.453Z
You do know that inverse trigonometric functions return a value between -90 and +90 right?
ProfRob
CC BY-SA 3.0
2016-05-26T15:03:35.613Z
I was not aware of this. I am using JavaScript for the calculation and found this documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2 So I made an educated guess and tried α=atan2((cos ε∗sin λ−sin ε∗tan β), cos λ) and the results are promising. Just need to add 360° if the result is negative to get the expected values. Can you confirm I am correct?
atarax42
CC BY-SA 3.0
2016-07-08T19:33:26.503Z
Yes, in many program languages atan2(x,y) gives the same result as atan(x/y), but in the correct quadrant.
AstroFloyd
CC BY-SA 3.0
2016-08-18T20:39:22.190Z
The rotation matrix formulation in that Wikipedia article leads to $\alpha = \mathrm{atan2}(\cos \beta \sin \lambda \cos \varepsilon - \sin \beta \sin \varepsilon, \cos \beta \cos \lambda)$, equivalent in most cases but avoiding an infinite term $\tan \beta$ at the ecliptic poles, costing one more trig function call.
Mike G
<fundamental-astronomy><coordinate>
Converting ecliptical to equatorial coordinates
atarax42
# Converting ecliptical to equatorial coordinates

(Asked by: username_0 on 2016-05-26)

When looking for a formula to convert polar ecliptic geocentric coordinates of an object to equatorial coordinates I find various sources that give these formulae (like [Wikipedia](https://en.wikipedia.org/wiki/Celestial_coordinate_system#Equatorial_.E2.86.90.E2.86.92_ecliptic)):

Declination $δ = \arcsin(\cos ε \times \sin β + \sin ε \times \cos β \times \sin λ)$  
Right ascension $α = \arctan((\cos ε \times \sin λ - \sin ε \times \tan β) / \cos λ)$

Where  
β = ecliptic geocentric latitude  
λ = ecliptic geocentric longitude  
ε = obliquity of the ecliptic

But when applying these formulae I get results like in the following list where β = 0° and ε = 23.4°:

```
 λ       δ        α
  0   0.0000   0.0000
 45  16.3095  42.5443
 90  23.4000  90.0000
135  16.3095 -42.5443
180   0.0000  -0.0000
225 -16.3095  42.5443
270 -23.4000  90.0000
315 -16.3095 -42.5443
360  -0.0000  -0.0000

```

The values for declination seem good, but right ascension values seem to lack some sort of adjustment to the quadrant of the full circle (just a guess). But nowhere did I find any mentioning of this. Can you help? Thanks.

**Tags:** fundamental-astronomy, coordinate

> **Comments:**
> **username_1**: This is a standard problem with using an arctan function and the reason that a lot of programming languages have two functions the simple one like you appear to have used and a more complex one that takes two parameters for when you are dividing (before the arctan function) as in this case. Here is a video describing the issue (https://youtu.be/_JbkTK17MrY).  
> **username_2**: You do know that inverse trigonometric functions return a value between -90 and +90 right?  
> **username_0**: I was not aware of this. I am using JavaScript for the calculation and found this documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2 So I made an educated guess and tried α=atan2((cos ε∗sin λ−sin ε∗tan β), cos λ) and the results are promising. Just need to add 360° if the result is negative to get the expected values. Can you confirm I am correct?  
> **username_3**: Yes, in many program languages atan2(x,y) gives the same result as atan(x/y), but in the correct quadrant.  
> **username_4**: The rotation matrix formulation in that Wikipedia article leads to $\alpha = \mathrm{atan2}(\cos \beta \sin \lambda \cos \varepsilon - \sin \beta \sin \varepsilon, \cos \beta \cos \lambda)$, equivalent in most cases but avoiding an infinite term $\tan \beta$ at the ecliptic poles, costing one more trig function call.  

---

## 1 answers

### Answer by username_5 on 2017-01-11. Score: 3

*Convert commments to community wiki*

This is a standard problem with using an arctan function (inverse tan function returns a value between -90 and +90). A lot of programming languages have two functions the simple one like you appear to have used and a more complex one that takes two parameters for when you are dividing (before the arctan function) as in this case. (This is described in further detail at (<http://youtu.be/_JbkTK17MrY>)

In Java you can use `α=atan2((cos ε∗sin λ−sin ε∗tan β), cos λ)` you may need to add 360 if the angle returned is negative.

An alternative is `α=atan2(cosβsinλcosε−sinβsinε,cosβcosλ)`. This is equivalent in most cases but avoids an infinite term `tanβtan⁡β` at the ecliptic poles, costing one more trig function call.

> **Comments:**
> **username_6**: Just wanted to say thank you for that last paragraph. I've been trying to implement the algorithms from Astronomical Algorithms, and I realized that the `tan(β)` term was a ticking timebomb.  

---

