From 13b13a0f3f1d41d4d22f2bbcbddc5bfa70a58e4e Mon Sep 17 00:00:00 2001 From: Don Cross Date: Thu, 3 Feb 2022 22:05:12 -0500 Subject: [PATCH] C Astronomy_EclipticGeoMoon implemented. This is a thin wrapper function for the internal function CalcMoon, which has already been extensively validated. It will enable outside users to search for ascending and descending nodes of the Moon, or to calculate ecliptic spherical coordinates for the Moon for any other useful purpose. --- generate/template/astronomy.c | 36 +++++++++++++++++++++++++++++++++++ source/c/README.md | 30 +++++++++++++++++++++++++++++ source/c/astronomy.c | 36 +++++++++++++++++++++++++++++++++++ source/c/astronomy.h | 1 + 4 files changed, 103 insertions(+) diff --git a/generate/template/astronomy.c b/generate/template/astronomy.c index da657653..d23485d2 100644 --- a/generate/template/astronomy.c +++ b/generate/template/astronomy.c @@ -1893,6 +1893,8 @@ $ASTRO_ADDSOL() * [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) * by Montenbruck and Pfleger. * + * To calculate ecliptic spherical coordinates instead, see #Astronomy_EclipticGeoMoon. + * * @param time The date and time for which to calculate the Moon's position. * @return The Moon's position as a vector in J2000 Cartesian equatorial (EQJ) coordinates. */ @@ -1928,6 +1930,40 @@ astro_vector_t Astronomy_GeoMoon(astro_time_t time) } +/** + * @brief Calculates spherical ecliptic geocentric position of the Moon. + * + * Given a time of observation, calculates the Moon's geocentric position + * in ecliptic spherical coordinates. Provides the ecliptic latitude and + * longitude in degrees, and the geocentric distance in astronomical units (AU). + * The ecliptic longitude is measured relative to the equinox of date. + * + * This algorithm is based on the Nautical Almanac Office's *Improved Lunar Ephemeris* of 1954, + * which in turn derives from E. W. Brown's lunar theories from the early twentieth century. + * It is adapted from Turbo Pascal code from the book + * [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) + * by Montenbruck and Pfleger. + * + * To calculate an equatorial J2000 vector instead, use #Astronomy_GeoMoon. + * + * @param time The date and time for which to calculate the Moon's position. + * @return The Moon's position expressed in ecliptic coordinates using the mean equinox of date. + */ +astro_spherical_t Astronomy_EclipticGeoMoon(astro_time_t time) +{ + astro_spherical_t sphere; + + CalcMoon(time.tt / 36525.0, &sphere.lon, &sphere.lat, &sphere.dist); + + /* Convert angles from radians to degrees. */ + sphere.lon *= RAD2DEG; + sphere.lat *= RAD2DEG; + + sphere.status = ASTRO_SUCCESS; + return sphere; +} + + /** * @brief Calculates equatorial geocentric position and velocity of the Moon at a given time. * diff --git a/source/c/README.md b/source/c/README.md index 96ed855d..c02127a7 100644 --- a/source/c/README.md +++ b/source/c/README.md @@ -466,6 +466,34 @@ Given coordinates relative to the Earth's equator at J2000 (the instant of noon +--- + + +### Astronomy_EclipticGeoMoon(time) ⇒ [`astro_spherical_t`](#astro_spherical_t) + +**Calculates spherical ecliptic geocentric position of the Moon.** + + + +Given a time of observation, calculates the Moon's geocentric position in ecliptic spherical coordinates. Provides the ecliptic latitude and longitude in degrees, and the geocentric distance in astronomical units (AU). The ecliptic longitude is measured relative to the equinox of date. + +This algorithm is based on the Nautical Almanac Office's *Improved Lunar Ephemeris* of 1954, which in turn derives from E. W. Brown's lunar theories from the early twentieth century. It is adapted from Turbo Pascal code from the book [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) by Montenbruck and Pfleger. + +To calculate an equatorial J2000 vector instead, use [`Astronomy_GeoMoon`](#Astronomy_GeoMoon). + + + +**Returns:** The Moon's position expressed in ecliptic coordinates using the mean equinox of date. + + + +| Type | Parameter | Description | +| --- | --- | --- | +| [`astro_time_t`](#astro_time_t) | `time` | The date and time for which to calculate the Moon's position. | + + + + --- @@ -643,6 +671,8 @@ Given a time of observation, calculates the Moon's position as a vector. The vec This algorithm is based on the Nautical Almanac Office's *Improved Lunar Ephemeris* of 1954, which in turn derives from E. W. Brown's lunar theories from the early twentieth century. It is adapted from Turbo Pascal code from the book [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) by Montenbruck and Pfleger. +To calculate ecliptic spherical coordinates instead, see [`Astronomy_EclipticGeoMoon`](#Astronomy_EclipticGeoMoon). + **Returns:** The Moon's position as a vector in J2000 Cartesian equatorial (EQJ) coordinates. diff --git a/source/c/astronomy.c b/source/c/astronomy.c index 6a5c76ac..e37804f9 100644 --- a/source/c/astronomy.c +++ b/source/c/astronomy.c @@ -2082,6 +2082,8 @@ static void CalcMoon( * [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) * by Montenbruck and Pfleger. * + * To calculate ecliptic spherical coordinates instead, see #Astronomy_EclipticGeoMoon. + * * @param time The date and time for which to calculate the Moon's position. * @return The Moon's position as a vector in J2000 Cartesian equatorial (EQJ) coordinates. */ @@ -2117,6 +2119,40 @@ astro_vector_t Astronomy_GeoMoon(astro_time_t time) } +/** + * @brief Calculates spherical ecliptic geocentric position of the Moon. + * + * Given a time of observation, calculates the Moon's geocentric position + * in ecliptic spherical coordinates. Provides the ecliptic latitude and + * longitude in degrees, and the geocentric distance in astronomical units (AU). + * The ecliptic longitude is measured relative to the equinox of date. + * + * This algorithm is based on the Nautical Almanac Office's *Improved Lunar Ephemeris* of 1954, + * which in turn derives from E. W. Brown's lunar theories from the early twentieth century. + * It is adapted from Turbo Pascal code from the book + * [Astronomy on the Personal Computer](https://www.springer.com/us/book/9783540672210) + * by Montenbruck and Pfleger. + * + * To calculate an equatorial J2000 vector instead, use #Astronomy_GeoMoon. + * + * @param time The date and time for which to calculate the Moon's position. + * @return The Moon's position expressed in ecliptic coordinates using the mean equinox of date. + */ +astro_spherical_t Astronomy_EclipticGeoMoon(astro_time_t time) +{ + astro_spherical_t sphere; + + CalcMoon(time.tt / 36525.0, &sphere.lon, &sphere.lat, &sphere.dist); + + /* Convert angles from radians to degrees. */ + sphere.lon *= RAD2DEG; + sphere.lat *= RAD2DEG; + + sphere.status = ASTRO_SUCCESS; + return sphere; +} + + /** * @brief Calculates equatorial geocentric position and velocity of the Moon at a given time. * diff --git a/source/c/astronomy.h b/source/c/astronomy.h index 2e566bb6..e3b0ffeb 100644 --- a/source/c/astronomy.h +++ b/source/c/astronomy.h @@ -1120,6 +1120,7 @@ astro_func_result_t Astronomy_HelioDistance(astro_body_t body, astro_time_t time astro_vector_t Astronomy_HelioVector(astro_body_t body, astro_time_t time); astro_vector_t Astronomy_GeoVector(astro_body_t body, astro_time_t time, astro_aberration_t aberration); astro_vector_t Astronomy_GeoMoon(astro_time_t time); +astro_spherical_t Astronomy_EclipticGeoMoon(astro_time_t time); astro_state_vector_t Astronomy_GeoMoonState(astro_time_t time); astro_state_vector_t Astronomy_GeoEmbState(astro_time_t time); astro_libration_t Astronomy_Libration(astro_time_t time);