-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLunar.h
158 lines (130 loc) · 3.56 KB
/
Lunar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*****************************************************************************\
* Lunar.h
*
* Lunar is a class that can calculate lunar fundmentals for any reasonable
* time.
*
* author: mark huss ([email protected])
* Based on Bill Gray's open-source code at projectpluto.com
*
\*****************************************************************************/
#if !defined( LUNAR__H )
#define LUNAR__H
#include <math.h>
#include "AstroOps.h"
// A struct to hold the fundmental elements
// The member names should be familiar to Meeus fans ;-)
//
struct LunarFundamentals {
double Lp;
double D;
double M;
double Mp;
double F;
double A1;
double A2;
double A3;
double T;
LunarFundamentals():Lp(0.),D(0.),M(0.),Mp(0.),F(0.),A1(0.),A2(0.),A3(0.),T(0.) {}
};
// terms for longitude & radius
//
static const int N_LTERM1 = 60;
struct LunarTerms1 {
char d, m, mp, f;
long sl, sr;
};
// terms for latitude
//
static const int N_LTERM2 = 60;
struct LunarTerms2 {
char d, m, mp, f;
long sb;
};
// our main class -- calculates Lunar fundamentals, lat, lon & distance
//
class Lunar {
public:
// default c'tor
Lunar() : m_initialized( false ), m_lon(-1.), m_lat(-1.), m_r(-1.)
{}
// data & time c'tor
// t = decimal julian centuries
Lunar( double t )
{
calcFundamentals( t );
}
static const double SYNODIC_MONTH = 29.530588861;
double illuminatedFraction();
static double ageOfMoonInDays( double jd );
// calculates the fundamanentals given the time
// t = decimal julian centuries
//
void calcFundamentals( double t );
//
// NOTE: calcFundamentals() must be called before calling the functions
// below, or an invalid result (-1.) will be returned.
//
double phaseAngle();
// returns lunar latitude
double latitude(); // returns -1 if not initialized
double latitudeRadians() { // returns -1 if not initialized
return ( m_initialized ) ? Astro::toRadians( latitude() ) : -1.;
}
// returns lunar longitude
double longitude() // returns -1 if not initialized
{
if ( m_lon < 0. )
calcLonRad();
return m_lon;
}
double longitudeRadians() // returns -1 if not initialized
{
return ( m_initialized ) ? Astro::toRadians( longitude() ) : -1.;
}
// returns lunar distance
double radius() // returns -1 if not initialized
{
if ( m_r < 0. )
calcLonRad();
return m_r;
}
// calculate all three location elements of the spec'd body at the given time
//
void calcAllLocs(
double& lon, // returned longitude
double& lat, // returned latitude
double& rad, // returned radius vector
double t) // time in decimal centuries
{
calcFundamentals( t );
lon = longitudeRadians();
lat = latitudeRadians();
rad = radius();
}
private:
// reduce (0 < d < 360) a positive angle and convert to radians
//
double normalize( double d ) {
return Astro::toRadians( AstroOps::normalizeDegrees( d ) );
}
// calculate an individual fundimental
// tptr - points to array of doubles
// t - time in decimal Julian centuries
//
double getFund( const double* tptr, double t );
// calculate longitude and radius
//
// NOTE: calcFundamentals() must have been called first
//
void calcLonRad();
// ***** data *****
// our calculated fundmentals
//
LunarFundamentals m_f;
// true if calcFundamentals has been called
bool m_initialized;
// longitude, latitude, and radius (stored in _degrees_)
double m_lon, m_lat, m_r;
};
#endif /* #if !defined( LUNAR__H ) */