<p>I have to agree with PM2Ring.  The issue is that you're incorrectly determining the quadrant of the longitude from the <code>atan</code> function, by ignoring the individual signs of <code>x</code> and <code>y</code> in the provided algorithm. If you use <code>atan2</code>, that's handled for you.</p>
<p>Using the following:</p>
<pre><code>def from_equatoral_to_ecliptique2(ra, dec, ob):
    ob = radians(dms_to_dd(ob))
    ra = radians(dms_to_dd(ra) * 15)
    dec = radians(dms_to_dd(dec))

    beta = asin(sin(dec) * cos(ob) - cos(dec) * sin(ob) * sin(ra))
    y = sin(ra) * cos(ob) + tan(dec) * sin(ob)
    x = cos(ra)

    lambda_prime = math.atan2(y, x)

    return degrees(lambda_prime), degrees(beta)
</code></pre>
<p>Returns <code>-93.14846713531182 -5.613954797554798</code> as the pair longitude, latitude (with the fix for negative declinations included)</p>
<p>And <span class="math-container">$360° +  -93.1° = 266.9°$</span>, which is still a bit off from what you're getting from the FrostyDew website, but is at least closer.</p>
<p>That said, the Frostydew website's value appears to disagree with the  the NASA/IPAC  Extragalactic Database's calculator, which converts the provided Equatorial coordinate values to <a href="https://ned.ipac.caltech.edu/coordinate_calculator?in_csys=Equatorial&amp;in_equinox=J2000.0&amp;obs_epoch=2000.0&amp;ra=17h45m40s&amp;dec=-29d0m28s&amp;pa=0.0&amp;out_csys=Ecliptic&amp;out_equinox=J2000.0" rel="nofollow noreferrer">266.85° Ecliptic Longitude, -5.60 Ecliptic Latitude</a>, and with the Ecliptic longitude of Sagittarius A* from Wolfram Alpha, which gives <a href="https://www.wolframalpha.com/input?i=ecliptic%20longitude%20sagittarius%20A*" rel="nofollow noreferrer">266 degrees 51 arcminutes</a></p>

CC BY-SA 4.0
2022-09-05T16:10:59.697Z
But isn't -93.1 the latitude value? I am getting the same result by the way. The latitude value should be close to 52 while the longitude value should be close 264. Could u please look at the result of the website again?
dildeolupbiten
CC BY-SA 4.0
2022-09-05T16:24:18.293Z
@dildeolupbiten  I think there's a bug in the website you've chosen to use to check your values. I used Caltech's coordinate calculator:   https://ned.ipac.caltech.edu/coordinate_calculator?in_csys=Equatorial&in_equinox=J2000.0&obs_epoch=2000.0&ra=17h45m40s&dec=-29d0m28s&pa=0.0&out_csys=Ecliptic&out_equinox=J2000.0
notovny
CC BY-SA 4.0
2022-09-05T16:27:35.887Z
So we are getting same results. But It should be 264.  Because Sagittarius is between 240 and 270 degrees. So 264 degree corresponds to 24 degree Sagittarius, that's why it is called Sagittarius A. Where am I making mistake? :/ Also, the 24 of 24 Sagittarius A should come from longitude, not latitude.
dildeolupbiten
CC BY-SA 4.0
2022-09-05T16:38:43.237Z
@dildeolupbiten The astronomical Sagittarius constellation does not cover the same amount of the ecliptic as Astrological Sagittarius, the latter is hard-pinned to 240° to 270°. Sagittarius A* is named because it's in the Sagittarius constellation.
notovny
CC BY-SA 4.0
2022-09-05T16:40:55.173Z
I know that but Sagittarius A is at 24 degree of Sagittarius. And 24 degree Sagittarius equals to 264 degree.
dildeolupbiten
CC BY-SA 4.0
2022-09-05T16:48:24.243Z
@dildeolupbiten   The [Ecliptic longitude of Sagittarius A* is 266° 51'](https://www.wolframalpha.com/input?i=ecliptic+longitude+sagittarius+A*) I don't know why you're insisting it has to be 264°, when it's clearly not.
notovny
CC BY-SA 4.0
2022-09-05T16:51:13.863Z
Oh sorry, ok ok, my mistake. Thank you very much by the way. My head got overloaded, i saw my mistake.
dildeolupbiten
CC BY-SA 4.0
2022-09-05T16:04:38.027Z
2022-09-05T17:28:29.260Z
2022-09-05T17:28:29.260Z
notovny
<p>I would like to convert equatoral coordinates to ecliptique coordinates. I am following the source below:</p>
<p><a href="https://books.google.com.tr/books?id=DwJfCtzaVvYC&amp;pg=PR6&amp;lpg=PR6&amp;dq=Equatorial%20to%20Ecliptic%20coordinates%20calculator&amp;source=bl&amp;ots=95o4XRaspP&amp;sig=ACfU3U0hphnN7UHMWLuw3M0Sp6k5gKND8w&amp;hl=en&amp;sa=X&amp;ved=2ahUKEwj8gavV0P35AhWMR_EDHfzQBmIQ6AF6BAguEAM#v=onepage&amp;q=Equatorial%20to%20Ecliptic%20coordinates%20calculator&amp;f=false" rel="nofollow noreferrer">Practical Astronomy with Your Calculator</a></p>
<p>The formula I am using is:</p>
<p><a href="https://i.sstatic.net/PBNF9.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PBNF9.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/LoVP2.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LoVP2.jpg" alt="enter image description here" /></a></p>
<p>When I solve this example, I find the same value. And I am checking the result using the website below:</p>
<p><a href="https://frostydrew.org/utilities.dc/convert/tool-eq_coordinates/" rel="nofollow noreferrer">https://frostydrew.org/utilities.dc/convert/tool-eq_coordinates/</a></p>
<p><a href="https://i.sstatic.net/ujMvb.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ujMvb.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/s49IC.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/s49IC.jpg" alt="enter image description here" /></a></p>
<p>As you see the results are same.</p>
<p>However when I want to find the ecliptic coordinates of Sagittarius A, I am getting different results:</p>
<p>Right Ascension of Sagittarius A is: 17h 45m 40.0409s
Declination of Sagittarius A is: −29° 0′ 28.118″</p>
<p>I found the results in the previous example with the following program, and the result was the same when I encountered the results on the site I mentioned to you.</p>
<p>I tried the same Python program this time to find the ecliptic coordinates of Sagittarius A, but the results were very different from the results on the site I mentioned.</p>
<pre><code>from math import cos, sin, tan, asin, atan, radians, degrees


def dd_to_dms(dd):
    degree = int(dd)
    minute = int((dd - degree) * 60)
    second = round(float((dd - degree - minute / 60) * 3600))
    return f&quot;{degree}\u00b0 {minute}\' {second}\&quot;&quot;


def dms_to_dd(dms):
    dms = dms.replace(&quot;\u00b0&quot;, &quot; &quot;).replace(&quot;\'&quot;, &quot; &quot;).replace(&quot;\&quot;&quot;, &quot; &quot;)
    degree = int(dms.split(&quot; &quot;)[0])
    minute = float(dms.split(&quot; &quot;)[1]) / 60
    second = float(dms.split(&quot; &quot;)[2]) / 3600
    return degree + minute + second


def from_equatoral_to_ecliptique(ra, dec, ob):
    ob = dms_to_dd(ob)
    ra = dms_to_dd(ra) * 15
    dec = dms_to_dd(dec)
    lat = (sin(radians(ra)) * cos(radians(ob)) + tan(radians(dec)) * sin(radians(ob))) / cos(radians(ra))
    lon = sin(radians(dec)) * cos(radians(ob)) - cos(radians(dec)) * sin(radians(ra)) * sin(radians(ob))
    return degrees(atan(lat)), degrees(asin(lon))


x, y = from_equatoral_to_ecliptique(
    ra=&quot;17°45'40.0409\&quot;&quot;,
    dec=&quot;-29°0'28.118&quot;,
    ob=&quot;23°26'0\&quot;&quot;
)
print(x, y)
</code></pre>
<p>When I run this program, I am getting the results below:</p>
<pre><code>86.85130704210478 -5.598002197452088
</code></pre>
<p>In order to remove the ambiguity of the longitude value, as mentioned in the article I shared with you, I am adding 180 degrees to the result. But when I add 180, the longitude value becomes <code>174.40199780254792</code></p>
<p>But when I check this value using the website I mentioned, I am seeing that the result equals to <code>264.862492</code>.
<a href="https://i.sstatic.net/N2INp.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/N2INp.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/Kng2A.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Kng2A.jpg" alt="enter image description here" /></a></p>
<p>I wonder what I am missing while trying to find the ecliptic coordinates of Sagittarius A. And I would like learn why I found the result similar in the first example but different in the second example.</p>
<p>Thanks in advance.</p>

CC BY-SA 4.0
2022-09-05T14:03:27.770Z
I was initially mis-led by RA being quoted as 17° in the script, but later this being converted to actual decimal degrees. While this works numerically in this case, this sloppy treatment of units is IMHO not ideal and dedicated treatment should be sought
planetmaker
CC BY-SA 4.0
2022-09-05T14:06:34.207Z
The main problem is, I made 2 examples trying to find ecliptic coordinates using equatoral coordinates. In the first of these examples, I got the same results as the website I used to validate the result. In the second example, I got a different result. And I wonder why this happened. :/
dildeolupbiten
CC BY-SA 4.0
2022-09-05T14:11:33.890Z
BTW, you should use `atan2` to get the correct quadrant.
PM 2Ring
CC BY-SA 4.0
2022-09-05T14:25:25.380Z
There's an issue with your `dms_to_dd` function improperly handling the minutes and seconds value of negative dms input (it takes them in the wrong direction, so that your input value of `"-29°0'28.118"` outputs `-28.992189444444445` ) but that's not the major issue.,
notovny
CC BY-SA 4.0
2022-09-05T14:58:13.367Z
@RM 2Ring, for this example, atan and atan2 returns the same value. And this is not related to the problem.
dildeolupbiten
CC BY-SA 4.0
2022-09-05T15:00:10.527Z
@notovny, agreed. I fixed that part but still getting the longitude value as `-5.613618436571124`. When I add 180 to this value, i get `174.38638156342887`. But I should have gotten a value close to `264.86`
dildeolupbiten
<coordinate><ecliptic>
Problem in converting equatoral coordinates to ecliptic coordinates
dildeolupbiten
# Problem in converting equatoral coordinates to ecliptic coordinates

(Asked by: username_0 on 2022-09-05)

I would like to convert equatoral coordinates to ecliptique coordinates. I am following the source below:
Practical Astronomy with Your Calculator
The formula I am using is:


When I solve this example, I find the same value. And I am checking the result using the website below:
https://frostydrew.org/utilities.dc/convert/tool-eq_coordinates/


As you see the results are same.
However when I want to find the ecliptic coordinates of Sagittarius A, I am getting different results:
Right Ascension of Sagittarius A is: 17h 45m 40.0409s
Declination of Sagittarius A is: −29° 0′ 28.118″
I found the results in the previous example with the following program, and the result was the same when I encountered the results on the site I mentioned to you.
I tried the same Python program this time to find the ecliptic coordinates of Sagittarius A, but the results were very different from the results on the site I mentioned.
from math import cos, sin, tan, asin, atan, radians, degrees


def dd_to_dms(dd):
    degree = int(dd)
    minute = int((dd - degree) * 60)
    second = round(float((dd - degree - minute / 60) * 3600))
    return f"{degree}\u00b0 {minute}\' {second}\""


def dms_to_dd(dms):
    dms = dms.replace("\u00b0", " ").replace("\'", " ").replace("\"", " ")
    degree = int(dms.split(" ")[0])
    minute = float(dms.split(" ")[1]) / 60
    second = float(dms.split(" ")[2]) / 3600
    return degree + minute + second


def from_equatoral_to_ecliptique(ra, dec, ob):
    ob = dms_to_dd(ob)
    ra = dms_to_dd(ra) * 15
    dec = dms_to_dd(dec)
    lat = (sin(radians(ra)) * cos(radians(ob)) + tan(radians(dec)) * sin(radians(ob))) / cos(radians(ra))
    lon = sin(radians(dec)) * cos(radians(ob)) - cos(radians(dec)) * sin(radians(ra)) * sin(radians(ob))
    return degrees(atan(lat)), degrees(asin(lon))


x, y = from_equatoral_to_ecliptique(
    ra="17°45'40.0409\"",
    dec="-29°0'28.118",
    ob="23°26'0\""
)
print(x, y)

When I run this program, I am getting the results below:
86.85130704210478 -5.598002197452088

In order to remove the ambiguity of the longitude value, as mentioned in the article I shared with you, I am adding 180 degrees to the result. But when I add 180, the longitude value becomes 174.40199780254792
But when I check this value using the website I mentioned, I am seeing that the result equals to 264.862492.


I wonder what I am missing while trying to find the ecliptic coordinates of Sagittarius A. And I would like learn why I found the result similar in the first example but different in the second example.
Thanks in advance.

**Tags:** coordinate, ecliptic
> **Comments:**
> **username_1**: I was initially mis-led by RA being quoted as 17° in the script, but later this being converted to actual decimal degrees. While this works numerically in this case, this sloppy treatment of units is IMHO not ideal and dedicated treatment should be sought  
> **username_0**: The main problem is, I made 2 examples trying to find ecliptic coordinates using equatoral coordinates. In the first of these examples, I got the same results as the website I used to validate the result. In the second example, I got a different result. And I wonder why this happened. :/  
> **username_2**: BTW, you should use `atan2` to get the correct quadrant.  
> **username_3**: There's an issue with your `dms_to_dd` function improperly handling the minutes and seconds value of negative dms input (it takes them in the wrong direction, so that your input value of `"-29°0'28.118"` outputs `-28.992189444444445` ) but that's not the major issue.,  
> **username_0**: @RM 2Ring, for this example, atan and atan2 returns the same value. And this is not related to the problem.  
> **username_0**: @notovny, agreed. I fixed that part but still getting the longitude value as `-5.613618436571124`. When I add 180 to this value, i get `174.38638156342887`. But I should have gotten a value close to `264.86`  

---

## 1 answers

### Answer by username_3 on 2022-09-05. Score: 3

I have to agree with PM2Ring.  The issue is that you're incorrectly determining the quadrant of the longitude from the atan function, by ignoring the individual signs of x and y in the provided algorithm. If you use atan2, that's handled for you.
Using the following:
def from_equatoral_to_ecliptique2(ra, dec, ob):
    ob = radians(dms_to_dd(ob))
    ra = radians(dms_to_dd(ra) * 15)
    dec = radians(dms_to_dd(dec))

    beta = asin(sin(dec) * cos(ob) - cos(dec) * sin(ob) * sin(ra))
    y = sin(ra) * cos(ob) + tan(dec) * sin(ob)
    x = cos(ra)

    lambda_prime = math.atan2(y, x)

    return degrees(lambda_prime), degrees(beta)

Returns -93.14846713531182 -5.613954797554798 as the pair longitude, latitude (with the fix for negative declinations included)
And $360° +  -93.1° = 266.9°$, which is still a bit off from what you're getting from the FrostyDew website, but is at least closer.
That said, the Frostydew website's value appears to disagree with the  the NASA/IPAC  Extragalactic Database's calculator, which converts the provided Equatorial coordinate values to 266.85° Ecliptic Longitude, -5.60 Ecliptic Latitude, and with the Ecliptic longitude of Sagittarius A* from Wolfram Alpha, which gives 266 degrees 51 arcminutes

> **Comments:**
> **username_0**: But isn't -93.1 the latitude value? I am getting the same result by the way. The latitude value should be close to 52 while the longitude value should be close 264. Could u please look at the result of the website again?  
> **username_3**: @dildeolupbiten  I think there's a bug in the website you've chosen to use to check your values. I used Caltech's coordinate calculator:   https://ned.ipac.caltech.edu/coordinate_calculator?in_csys=Equatorial&in_equinox=J2000.0&obs_epoch=2000.0&ra=17h45m40s&dec=-29d0m28s&pa=0.0&out_csys=Ecliptic&out_equinox=J2000.0  
> **username_0**: So we are getting same results. But It should be 264.  Because Sagittarius is between 240 and 270 degrees. So 264 degree corresponds to 24 degree Sagittarius, that's why it is called Sagittarius A. Where am I making mistake? :/ Also, the 24 of 24 Sagittarius A should come from longitude, not latitude.  
> **username_3**: @dildeolupbiten The astronomical Sagittarius constellation does not cover the same amount of the ecliptic as Astrological Sagittarius, the latter is hard-pinned to 240° to 270°. Sagittarius A* is named because it's in the Sagittarius constellation.  
> **username_0**: I know that but Sagittarius A is at 24 degree of Sagittarius. And 24 degree Sagittarius equals to 264 degree.  
> **username_3**: @dildeolupbiten   The [Ecliptic longitude of Sagittarius A* is 266° 51'](https://www.wolframalpha.com/input?i=ecliptic+longitude+sagittarius+A*) I don't know why you're insisting it has to be 264°, when it's clearly not.  
> **username_0**: Oh sorry, ok ok, my mistake. Thank you very much by the way. My head got overloaded, i saw my mistake.  

---

