11#include <QCoreApplication>
17using namespace KHolidays;
49static double phaseAngle(int64_t unixmsec);
55 const QTime midnight(0, 0, 0);
61 if (startAngle > endAngle) {
63 }
else if (startAngle < 90.0 && endAngle > 90.0) {
65 }
else if (startAngle < 180.0 && endAngle > 180.0) {
67 }
else if (startAngle < 270.0 && endAngle > 270.0) {
69 }
else if (endAngle < 90.0) {
71 }
else if (endAngle < 180.0) {
73 }
else if (endAngle < 270.0) {
75 }
else if (endAngle < 360.0) {
91constexpr int64_t epoch = 315446400000;
92constexpr double elonge = 278.833540;
93constexpr double elongp = 282.596403;
94constexpr double earthEcc = 0.016718;
95static const double ecPrefactor = sqrt((1 + earthEcc) / (1 - earthEcc));
97constexpr double mmlong = 64.975464;
98constexpr double mmlongp = 349.383063;
100static double fixAngle(
double degrees)
102 return degrees - floor(degrees / 360.0) * 360.0;
105static constexpr double radToDeg(
double rad)
107 return rad / std::numbers::pi * 180.0;
110static constexpr double degToRad(
double deg)
112 return deg / 180.0 * std::numbers::pi;
115constexpr double epsilon = 1e-6;
117static double kepler(
double m,
double ecc)
123 delta = e - ecc * sin(e) - mrad;
124 e -= delta / (1 - ecc * cos(e));
125 }
while (abs(delta) > epsilon);
129static double phaseAngle(int64_t unixmsec)
131 int64_t msec = unixmsec - epoch;
133 double sunMeanAnomaly = fixAngle(msec * (360.0 / 365.2422 / 86400000.0) + elonge - elongp);
134 double trueAnomaly = 2 *
radToDeg(atan(ecPrefactor * tan(kepler(sunMeanAnomaly, earthEcc) / 2)));
135 double geocentricEclipticLong = fixAngle(trueAnomaly + elongp);
137 double moonMeanLong = fixAngle(msec * (13.1763966 / 86400000.0) + mmlong);
138 double moonMeanAnomaly = fixAngle(moonMeanLong - msec * (0.1114041 / 86400000.0) - mmlongp);
139 double evection = 1.2739 * sin(
degToRad(2 * (moonMeanLong - geocentricEclipticLong) - moonMeanAnomaly));
140 double annualEquation = 0.1858 * sin(
degToRad(sunMeanAnomaly));
141 double a3 = 0.37 * sin(
degToRad(sunMeanAnomaly));
142 double correctedAnomaly = moonMeanAnomaly + evection - annualEquation - a3;
143 double centreCorrection = 6.2886 * sin(
degToRad(correctedAnomaly));
144 double a4 = 0.214 * sin(
degToRad(2 * correctedAnomaly));
145 double correctedLong = moonMeanLong + evection + centreCorrection - annualEquation + a4;
146 double variation = 0.6583 * sin(
degToRad(2 * (correctedLong - geocentricEclipticLong)));
147 double trueLong = correctedLong + variation;
149 return fixAngle(trueLong - geocentricEclipticLong);
152#include "moc_lunarphase.cpp"
static QString phaseNameAtDate(const QDate &date)
Return the lunar phase as a text string for the specified date.
static Phase phaseAtDate(const QDate &date)
Return the lunar phase for the specified Gregorian date.
Phase
Phases of the moon, in traditional English notation.
@ FullMoon
Full moon phase.
@ FirstQuarter
First quarter of moon phase.
@ None
Indication for error.
@ LastQuarter
Last quarter of moon phase.
static QString phaseName(Phase phase)
Return the string representation of phase.
constexpr double radToDeg(double rad)
constexpr double degToRad(double deg)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
QDate addDays(qint64 ndays) const const
qint64 toMSecsSinceEpoch() const const