Sun position
Sun position algorithm
moon.h File Reference

moon.h - routines to calculate the Moon's position More...

Go to the source code of this file.

Functions

void moon_nrelApp2 (double t_cy, const Sky0_Nut1980 *nut, V3D_Vector *appV, double *dist_au)
 Calculates the Moon's position in geocentric apparent coordinates, using the NREL Moon Position Algorithm. More...
 
void moon_nrelApparent (double j2kTT_cy, Sky_TrueEquatorial *pos)
 Calculate the Moon's position as a unit vector and a distance, in apparent coordinates. More...
 
void moon_nrelTopocentric (double j2kdUtc, const Sky_DeltaTs *deltas, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
 Calls moon_nrelApparent() to calculate the Moon's position in apparent coordinates using the NREL Moon Position Algorithm, and then converts this to topocentric horizon coordinates at the specified site. More...
 
double moon_riseSet (int year, int month, int day, bool getMoonrise, const Sky_DeltaTs *deltas, const Sky_SiteProp *site, Sky_SiteHorizon *topo)
 Routine to calculate the time of moonrise or moonset for the day specified by year, month and day. More...
 

Detailed Description

moon.h - routines to calculate the Moon's position

Author
David Hoadley

An implementation of the SAMPA (Moon Position Algorithm) from the National Renewable Energy Laboratory

Rectangular coordinates are used wherever possible, to minimise the unnecessary recalculation of trigonometric functions.

Reference:
Reda, I., Solar Eclipse Monitoring for Solar Energy Applications Using the Solar and Moon Position Algorithms. National Renewable Energy Laboratory Technical Report NREL/TP-3B0-47681, March 2010

Definition in file moon.h.

Function Documentation

◆ moon_nrelApp2()

void moon_nrelApp2 ( double  t_cy,
const Sky0_Nut1980 nut,
V3D_Vector appV,
double *  dist_au 
)

Calculates the Moon's position in geocentric apparent coordinates, using the NREL Moon Position Algorithm.

Parameters
[in]t_cyJulian centuries since J2000.0, TT timescale
[in]nutNutation terms and obliquity of the ecliptic
[out]appVPosition vector of Moon in apparent coordinates (unit vector i.e. direction cosines)
[out]dist_auGeocentric distance of the Moon (Astronomical Units)
Reference
Reda, I., "Solar Eclipse Monitoring for Solar Energy Applications Using the Solar and Moon Position Algorithms". National Renewable Energy Laboratory Technical Report NREL/TP-3B0-47681, March 2010

Definition at line 143 of file moon.c.

◆ moon_nrelApparent()

void moon_nrelApparent ( double  j2kTT_cy,
Sky_TrueEquatorial pos 
)

Calculate the Moon's position as a unit vector and a distance, in apparent coordinates.

It calls moon_nrelApp2() to obtain the Moon's position, after having called sky0_nutationSpa() to obtain the necessary nutation terms.

Parameters
[in]j2kTT_cyJulian centuries since J2000.0, TT timescale
[out]posTimestamped structure containing position data and the equation of the equinoxes
When to call this function
Because this function is computationally intensive, you may wish to limit your use of this function.
  • if you want the Moon's position at multiple sites simultaneously at a single time, call this function, then follow it with a call to routine sky0_appToTirs(), and then make a separate call to sky_siteTirsToTopo() for each of one those sites.
  • if you want the Moon's position at one or more sites at closely spaced times (e.g. for tracking the Moon), pass this function to the skyfast_init() function. skyfast_init() will call it for you several times, to fully calculate positions that will be saved and used later for interpolation by the skyfast_getApprox() function for tracking.
Alternatives:
  • If you want the Moon's position at a single site only at a single time, call moon_nrelTopocentric() instead, and it will call this function for you.
  • If you want the Moon's position at a single site for more than one time but the times are spaced more than an hour or so apart, once again call moon_nrelTopocentric() instead.
  • If you want to track the Moon, call skyfast_getApprox() instead. But this requires you to set up interpolation first with function skyfast_init() (and this function), as described above.

Definition at line 223 of file moon.c.

◆ moon_nrelTopocentric()

void moon_nrelTopocentric ( double  j2kdUtc,
const Sky_DeltaTs deltas,
const Sky_SiteProp site,
Sky_SiteHorizon topo 
)

Calls moon_nrelApparent() to calculate the Moon's position in apparent coordinates using the NREL Moon Position Algorithm, and then converts this to topocentric horizon coordinates at the specified site.

Parameters
[in]j2kdUtcUTC time in "J2KD" form - i.e days since J2000.0 (= JD - 2 451 545.0)
[in]deltasDelta T values, as set by the sky_initTime() (or sky_initTimeSimple() or sky_initTimeDetailed()) routines
[in]siteProperties of the observing site, particularly its geometric location on the surface of the Earth, as set by the sky_setSiteLocation() function (or sky_setSiteLoc2())
[out]topoTopocentric position, in both rectangular (unit vector) form, and as Azimuth and Elevation (altitude) angles

Examples
demo3_moon.c.

Definition at line 278 of file moon.c.

◆ moon_riseSet()

double moon_riseSet ( int  year,
int  month,
int  day,
bool  getMoonrise,
const Sky_DeltaTs deltas,
const Sky_SiteProp site,
Sky_SiteHorizon topo 
)

Routine to calculate the time of moonrise or moonset for the day specified by year, month and day.

This function uses the NREL MPA algorithm of moon_nrelTopocentric() to calculate the Moon's position.

Returns
Moonrise (or moonset) time for the day given in year, month and day (returned as a J2KD date (= JD - 2 451 545.0), UTC timescale). To view this as a local date and time, add this value to site->timezone_d and pass the result to function sky_j2kdToCalTime().
Parameters
[in]year,month,dayDate for which moonrise or moonset time is desired
[in]getMoonriseIf true, get moonrise time. If false, get moonset time
[in]deltasDelta T values, as set by the sky_initTime() (or sky_initTimeSimple() or sky_initTimeDetailed()) routines
[in]siteProperties of the observing site, particularly its geometric location on the surface of the Earth and its time zone, as set by the sky_setSiteLocation() function (or sky_setSiteLoc2()) and sky_setSiteTimeZone().
[out]topoOptional. Topocentric position of the Moon at rise or set, in both rectangular (unit vector) form, and as Azimuth and Elevation (altitude) angles. If you are not interested in these values, you can pass NULL to this parameter.

This routine uses an iterative approach. Three iterations seems to be enough.

Note
If the Moon does not rise (or set) on the specified day, this routine will return the time just before midnight on the previous day, or just after midnight on the next day, when the rise (or set) actually occurs. If the routine encounters an error, it will return 0.0

Definition at line 316 of file moon.c.