<p>Assuming you are calling <code>cEci</code> and have the units and sign conventions correct (longitudes are notoriously inconsistent as to which way is positive) then you should be able to calculate it almost as you have as:</p>

<pre><code>distance = sqrt(x*x + y*y + z*z)
RA = atan2(y/x)
# Normalize right ascension into the 0..2*PI range
if ( RA &lt; 0. ) 
  RA += PI + PI
Dec = asin(z/distance)
# Convert radians to hms and or degrees to taste
</code></pre>

<p>This code was taken from Bill Gray's <a href="https://github.com/Bill-Gray/sat_code" rel="nofollow noreferrer">sat_code</a>, specifically <code>observe.cpp</code>. Other bits of that code handle the conversion from a latitude, longitude, height (geodetic coordinates) to a X,Y,Z vector from the Earth center to the observing site (geocentric co-ordinates) and then the rotation by the Local Mean Sidereal Time (site longitude + GMST, where GMST is the Greenwich Mean Sidereal Time) and then the 2 vectors (Geocenter->Site and Geocenter->Sattelite) are added. However it looks <code>cEci</code> already has this as I see references to the flattening factor and LMST.</p>

<p>One thing to note with TLEs is they are not a very good representation of the satellite motion/orbit over long periods of times. You should make sure your TLEs are up-to-date or use something like SGP4 to apply the perturbations and update the TLEs.</p>

CC BY-SA 4.0
2018-07-26T20:27:38.863Z
2018-07-26T20:27:38.863Z
astrosnapper
<p>Using the library <a href="http://www.zeptomoby.com/satellites/" rel="nofollow noreferrer">OrbitTools</a> I can input a TLE and get back ECI coordinates. I want to find the RA DEC though, so I use </p>

<pre><code>right_ascension = atan(y / x) * 180.0 / PI;

declination = acos(z/ sqrt(x* x + y * y + z * z)) * 180.0 / PI;
</code></pre>

<p>I figure there is likely some constant I need to add (PI/2, PI, etc.) but comparing the calculated RA to that in the TLE, there is no constant that would fix it. </p>

<p>I also noticed x,y,z can be very low (on the order of ~100 km in some cases) which would suggest its measured from earth's surface, so I would need to add the earth's radius to x,y,z, but this also doesn't fix my problem. </p>

<p>Alternatively, I tried using the built in look angle function from OrbitTools, assuming that (0,0,0) (latitude, longitude, height) would be equivalent to RA DEC but... its not. Thanks!</p>

CC BY-SA 4.0
2018-07-25T07:59:27.193Z
Have you factored in your location on Earth relative to the coordinates of your target?
Mick
CC BY-SA 4.0
2018-07-25T15:20:52.010Z
Hi: you should always spell out your abbreviations (TLE, ECI). Don't assume everyone is aware of them.   Now, what is the source of your formulas?  Are they in the same unit system as the values OrbitTools accepts as input and generates as output?
Carl Witthoft
<satellite>
Help converting ECI to RA DEC
Gstein
# Help converting ECI to RA DEC

(Asked by: username_0 on 2018-07-25)

Using the library OrbitTools I can input a TLE and get back ECI coordinates. I want to find the RA DEC though, so I use 
right_ascension = atan(y / x) * 180.0 / PI;

declination = acos(z/ sqrt(x* x + y * y + z * z)) * 180.0 / PI;

I figure there is likely some constant I need to add (PI/2, PI, etc.) but comparing the calculated RA to that in the TLE, there is no constant that would fix it. 
I also noticed x,y,z can be very low (on the order of ~100 km in some cases) which would suggest its measured from earth's surface, so I would need to add the earth's radius to x,y,z, but this also doesn't fix my problem. 
Alternatively, I tried using the built in look angle function from OrbitTools, assuming that (0,0,0) (latitude, longitude, height) would be equivalent to RA DEC but... its not. Thanks!

**Tags:** satellite

> **Comments:**
> **username_1**: Have you factored in your location on Earth relative to the coordinates of your target?  
> **username_2**: Hi: you should always spell out your abbreviations (TLE, ECI). Don't assume everyone is aware of them.   Now, what is the source of your formulas?  Are they in the same unit system as the values OrbitTools accepts as input and generates as output?  

---

## 1 answers

### Answer by username_3 on 2018-07-26. Score: 1

Assuming you are calling cEci and have the units and sign conventions correct (longitudes are notoriously inconsistent as to which way is positive) then you should be able to calculate it almost as you have as:
distance = sqrt(x*x + y*y + z*z)
RA = atan2(y/x)
# Normalize right ascension into the 0..2*PI range
if ( RA < 0. ) 
  RA += PI + PI
Dec = asin(z/distance)
# Convert radians to hms and or degrees to taste

This code was taken from Bill Gray's sat_code, specifically observe.cpp. Other bits of that code handle the conversion from a latitude, longitude, height (geodetic coordinates) to a X,Y,Z vector from the Earth center to the observing site (geocentric co-ordinates) and then the rotation by the Local Mean Sidereal Time (site longitude + GMST, where GMST is the Greenwich Mean Sidereal Time) and then the 2 vectors (Geocenter->Site and Geocenter->Sattelite) are added. However it looks cEci already has this as I see references to the flattening factor and LMST.
One thing to note with TLEs is they are not a very good representation of the satellite motion/orbit over long periods of times. You should make sure your TLEs are up-to-date or use something like SGP4 to apply the perturbations and update the TLEs.


---

