<p>A few responses to my own question:</p>

<p>(a) TDB time isn't critical because it only varies from TT by a few milliseconds.</p>

<p>(b) The resulting vector was not ECI but the vector from the earth to the sun in the celestial frame.  I needed to build the celestial to terrestrial rotation matrix using iauC2t00a() (assuming zero polar motion since it's generally less than 20 meters), and then rotate the resulting pv (position, velocity) vector-pair into the terrestrial frame using iauRxpv().</p>

<p>(c) (Still no clue on this one.)</p>

CC BY-SA 3.0
2016-04-08T16:42:32.573Z
2016-04-08T16:42:32.573Z
Bryan
<p>If you are using SOFA, I'd recommend reading the IERS Convention 2010. Here is the link: <a href="http://iers-conventions.obspm.fr/2010officialinfo.php" rel="nofollow noreferrer">IERS Convention 2010</a>. Chapter 5 is where you should read... in it, it describes the procedures as well which functions in the SOFA library you should use.</p>

<p>Edit: The above link has moved. The new link is: <a href="https://www.iers.org/IERS/EN/Publications/TechnicalNotes/tn36.html" rel="nofollow noreferrer">IERS Convention 2010</a></p>

CC BY-SA 4.0
2017-07-02T23:18:20.487Z
2020-06-10T06:26:21.680Z
2020-06-10T06:26:21.680Z
Huy Pham
<p>I'd like to calculate the positions of the sun and moon in the ECEF coordinate system using the SOFA (<a href="http://www.iausofa.org/current_C.html" rel="nofollow">http://www.iausofa.org/current_C.html</a>) libraries given a Julian day input.</p>

<p>So far, I've got this process for the sun:  (1) convert Jd (UTC) to TAI, to TT, then to TDB, then (2) calculate earth position/velocity in heliocentric coordinates (iauEpv00), then (3) negate the terms to get ECI.</p>

<p>(a) I'm not sure if the process above is correct, especially since calculating TDB time requires a "dtr" parameter, which apparently you have to have TDB times to estimate using iauDtdb().</p>

<p>(b) I'm not sure how to convert the resulting vector from ECI to ECF, which is probably just a time-based rotation of the longitude, but how much time is elapsing?</p>

<p>(c) Not sure where to even start with the moon.</p>

CC BY-SA 3.0
2016-03-30T02:23:15.417Z
I started with SOFA because it was recommended to me as the "gold standard" of astronomical software -- is CSPICE on par with it in terms of accuracy?
Bryan
<the-sun><the-moon><positional-astronomy>
Solar / lunar positions in ECEF using SOFA C libraries
Bryan
# Solar / lunar positions in ECEF using SOFA C libraries

(Asked by: username_0 on 2016-03-22)

I'd like to calculate the positions of the sun and moon in the ECEF coordinate system using the SOFA (<http://www.iausofa.org/current_C.html>) libraries given a Julian day input.

So far, I've got this process for the sun: (1) convert Jd (UTC) to TAI, to TT, then to TDB, then (2) calculate earth position/velocity in heliocentric coordinates (iauEpv00), then (3) negate the terms to get ECI.

(a) I'm not sure if the process above is correct, especially since calculating TDB time requires a "dtr" parameter, which apparently you have to have TDB times to estimate using iauDtdb().

(b) I'm not sure how to convert the resulting vector from ECI to ECF, which is probably just a time-based rotation of the longitude, but how much time is elapsing?

(c) Not sure where to even start with the moon.

**Tags:** the-sun, the-moon, positional-astronomy

> **Comments:**
> **username_0**: I started with SOFA because it was recommended to me as the "gold standard" of astronomical software -- is CSPICE on par with it in terms of accuracy?  

---

## 2 answers

### Answer by username_0 on 2016-04-08. Score: 2

A few responses to my own question:

(a) TDB time isn't critical because it only varies from TT by a few milliseconds.

(b) The resulting vector was not ECI but the vector from the earth to the sun in the celestial frame. I needed to build the celestial to terrestrial rotation matrix using iauC2t00a() (assuming zero polar motion since it's generally less than 20 meters), and then rotate the resulting pv (position, velocity) vector-pair into the terrestrial frame using iauRxpv().

(c) (Still no clue on this one.)


---

### Answer by username_1 on 2017-07-02. Score: 2

If you are using SOFA, I'd recommend reading the IERS Convention 2010. Here is the link: [IERS Convention 2010](http://iers-conventions.obspm.fr/2010officialinfo.php). Chapter 5 is where you should read... in it, it describes the procedures as well which functions in the SOFA library you should use.

Edit: The above link has moved. The new link is: [IERS Convention 2010](https://www.iers.org/IERS/EN/Publications/TechnicalNotes/tn36.html)


---

