Calculation and exposure of the moon's age and phase.

To obtain the sun's true longitude, the Star::getlonEcl() function has been
created.  The moon's age is then calculated as the difference between the moon's
and sun's true longitudes.  The phase is then simply half of one minus the
cosine of the age.  Hence these calculations are very cheap compared to the rest
of the moon position calculations.  The algorithm is from:

    Duffett-Smith, Peter. Practical Astronomy With Your Calculator. 3rd ed.
Cambridge: Cambridge University Press, 1981. ISBN 0-521-28411-2.

The code can replicate the example in the book of Feb 26, 1979 at 16h UT, with
an age of -0.4767 degrees a phase of 0.0:

$ fgfs --aircraft=UFO --start-date-gmt=1979:02:26:16:00:00 --airport=EGLL \
--altitude=50000 --enable-hud

The calculated phase is 1.459e-5 and the age is -6.2908 (which is -0.43628
degrees).  For a recent full moon:

$ fgfs --aircraft=UFO --start-date-gmt=2015:11:25:22:44:00 --airport=EGLL \
--altitude=50000 --enable-hud

The calculated age is -3.1413 and the phase is 0.9999999778.
This commit is contained in:
Edward d'Auvergne 2015-12-10 20:03:56 +01:00
parent edcd42bc2d
commit 76ebd569d5
3 changed files with 24 additions and 0 deletions

View File

@ -211,4 +211,8 @@ void MoonPos::updatePosition(double mjd, double lst, double lat, Star *ourSun)
/* SG_LOG( SG_GENERAL, SG_INFO, /* SG_LOG( SG_GENERAL, SG_INFO,
"Ra = (" << (SGD_RADIANS_TO_DEGREES *rightAscension) "Ra = (" << (SGD_RADIANS_TO_DEGREES *rightAscension)
<< "), Dec= (" << (SGD_RADIANS_TO_DEGREES *declination) << ")" ); */ << "), Dec= (" << (SGD_RADIANS_TO_DEGREES *declination) << ")" ); */
// Moon age and phase calculation
age = lonEcl - ourSun->getlonEcl();
phase = (1 - cos(age)) / 2;
} }

View File

@ -39,6 +39,8 @@ private:
double xg, yg; // the moon's rectangular geocentric coordinates double xg, yg; // the moon's rectangular geocentric coordinates
double ye, ze; // the moon's rectangular equatorial coordinates double ye, ze; // the moon's rectangular equatorial coordinates
double distance; // the moon's distance to the earth double distance; // the moon's distance to the earth
double age; // the moon's age from 0 to 2pi
double phase; // the moon's phase
// void TexInit(); // This should move to the constructor eventually. // void TexInit(); // This should move to the constructor eventually.
// GLUquadricObj *moonObject; // GLUquadricObj *moonObject;
@ -64,6 +66,8 @@ public:
double getye() const; double getye() const;
double getze() const; double getze() const;
double getDistance() const; double getDistance() const;
double getAge() const;
double getPhase() const;
}; };
inline double MoonPos::getM() const inline double MoonPos::getM() const
@ -101,4 +105,14 @@ inline double MoonPos::getDistance() const
return distance; return distance;
} }
inline double MoonPos::getAge() const
{
return age;
}
inline double MoonPos::getPhase() const
{
return phase;
}
#endif // _MOONPOS_HXX_ #endif // _MOONPOS_HXX_

View File

@ -33,6 +33,7 @@ class Star : public CelestialBody
private: private:
double lonEcl; // the sun's true longitude
double xs, ys; // the sun's rectangular geocentric coordinates double xs, ys; // the sun's rectangular geocentric coordinates
double ye, ze; // the sun's rectangularequatorial rectangular geocentric coordinates double ye, ze; // the sun's rectangularequatorial rectangular geocentric coordinates
double distance; // the sun's distance to the earth double distance; // the sun's distance to the earth
@ -50,6 +51,7 @@ public:
double getye() const; double getye() const;
double getze() const; double getze() const;
double getDistance() const; double getDistance() const;
double getlonEcl() const;
}; };
@ -88,6 +90,10 @@ inline double Star::getDistance() const
return distance; return distance;
} }
inline double Star::getlonEcl() const
{
return lonEcl;
}
#endif // _STAR_HXX_ #endif // _STAR_HXX_