36 #include <tdeglobal.h>
37 #include <tdelocale.h>
40 #include "lunarphase.h"
42 LunarPhase::LunarPhase( Hemisphere hemisphere )
47 LunarPhase::~LunarPhase()
58 return( mHemisphere );
71 return( i18n(
"Northern" ) );
74 return( i18n(
"Southern" ) );
88 return( i18n(
"New Moon" ) );
91 return( i18n(
"Full Moon" ) );
94 return( i18n(
"First Quarter Moon" ) );
97 return( i18n(
"Last Quarter Moon" ) );
101 return( TQString() );
108 Phase retPhase = None;
111 TQTime noontime( 12, 0, 0 );
112 TQDateTime today( date, noontime );
113 double todayPer = percentFull( today.toTime_t() );
114 TQDateTime yesterday( date.addDays(-1), noontime );
115 double yesterdayPer = percentFull( yesterday.toTime_t() );
117 if ( ( todayPer < 0.50 ) && ( yesterdayPer > 0.50 ) ) {
119 }
else if ( ( todayPer > 99.50 ) && ( yesterdayPer < 99.50 ) ) {
123 TQTime sqt( 0, 0, 0 );
124 TQDateTime start( date, sqt );
125 double startPer = percentFull( start.toTime_t() );
127 TQTime eqt( 23, 59, 59 );
128 TQDateTime end( date, eqt );
129 double endPer = percentFull( end.toTime_t() );
131 if ( ( startPer <= 50 ) && ( endPer > 50 ) ) {
132 if ( mHemisphere == Northern ) {
138 if ( ( endPer <= 50 ) && ( startPer > 50 ) ) {
139 if ( mHemisphere == Northern ) {
187 #include <sys/cdefs.h>
214 #define PI 3.14159265358979323846
223 #define EPOCH_MINUS_1970 (20 * 365 + 5 - 1)
224 #define EPSILONg 279.403303
225 #define RHOg 282.768422
226 #define ECCEN 0.016713
227 #define lzero 318.351648
228 #define Pzero 36.340410
229 #define Nzero 318.510107
235 double LunarPhase::percentFull( uint tmpt )
const
237 double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
238 double A4, lprime, V, ldprime, D, Nm;
241 days = ( tmpt - EPOCH_MINUS_1970 * 86400 ) / 86400.0;
243 N = 360 * days / 365.242191;
245 Msol = N + EPSILONg - RHOg;
247 Ec = 360 / PI * ECCEN * sin(degreesToRadians(Msol));
248 LambdaSol = N + Ec + EPSILONg;
250 l = 13.1763966 * days + lzero;
252 Mm = l - (0.1114041 * days) - Pzero;
254 Nm = Nzero - (0.0529539 * days);
256 Ev = 1.2739 * sin(degreesToRadians(2*(l - LambdaSol) - Mm));
257 Ac = 0.1858 * sin(degreesToRadians(Msol));
258 A3 = 0.37 * sin(degreesToRadians(Msol));
259 Mmprime = Mm + Ev - Ac - A3;
260 Ec = 6.2886 * sin(degreesToRadians(Mmprime));
261 A4 = 0.214 * sin(degreesToRadians(2 * Mmprime));
262 lprime = l + Ev + Ec - Ac + A4;
263 V = 0.6583 * sin(degreesToRadians(2 * (lprime - LambdaSol)));
264 ldprime = lprime + V;
265 D = ldprime - LambdaSol;
266 return(50.0 * (1 - cos(degreesToRadians(D))));
273 double LunarPhase::degreesToRadians(
double degree )
const
275 return( degree * PI / 180 );
282 void LunarPhase::adj360(
double *degree )
const
287 else if( *degree > 360 )
Phase phase(const TQDate &date) const
Return the lunar phase for the specified Gregorian date.
TQString hemisphereStr() const
Return hemisphere as a clear text string.
Hemisphere hemisphere() const
Return the hemisphere.
void setHemisphere(Hemisphere hemisphere=Northern)
Set the hemisphere.
static TQString phaseName(Phase phase)
Return the string representation of phase.
static TQString hemisphereName(Hemisphere hemisphere)
Return the string representation of hemisphere.
TQString phaseStr(const TQDate &date) const
Return the lunar phase as a text string for the specified date.