1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU Lesser General Public License as published
7 //  by the Free Software Foundation; either version 3.0 of the License, or
8 //  any later version.
9 //
10 //  The GPSTk is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with GPSTk; if not, write to the Free Software Foundation,
17 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 //  This software was developed by Applied Research Laboratories at the
20 //  University of Texas at Austin.
21 //  Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 //  This software was developed by Applied Research Laboratories at the
28 //  University of Texas at Austin, under contract to an agency or agencies
29 //  within the U.S. Department of Defense. The U.S. Government retains all
30 //  rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 //  Pursuant to DoD Directive 523024
33 //
34 //  DISTRIBUTION STATEMENT A: This software has been approved for public
35 //                            release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 /**
40  * @file MoonPosition.hpp
41  * Returns the approximate position of the Moon at the given epoch in the
42  * ECEF system.
43  */
44 
45 #ifndef MOONPOSITION_HPP
46 #define MOONPOSITION_HPP
47 
48 #include <cmath>
49 #include <string>
50 
51 #include "CommonTime.hpp"
52 #include "Triple.hpp"
53 #include "GNSSconstants.hpp"
54 #include "AstronomicalFunctions.hpp"
55 #include "Vector.hpp"
56 #include "Matrix.hpp"
57 
58 
59 namespace gpstk
60 {
61 
62       /// @ingroup ephemcalc
63       //@{
64 
65       /** This class computes the approximate position of the Moon at
66        *  the given epoch in the ECEF system. It is limited between
67        *  March 1st, 1900 and February 28th, 2100.
68        *
69        * The class is based in the Meeus algorithms published in Meeus,
70        * l'Astronomie, June 1984, p348. This is a C++ implementation version
71        * of the FORTRAN version originally written by P.T. Wallace, Starlink
72        * Project. The FORTRAN version of Starlink project was available under
73        * the GPL license.
74        *
75        * Errors in position (RMS) are:
76        *
77        * \li Longitude: 3.7 arcsec.
78        * \li Latitude: 2.3 arcsec.
79        * \li Distance: 11 km.
80        *
81        * More information may be found in http://starlink.jach.hawaii.edu/
82        */
83    class MoonPosition
84    {
85    public:
86 
87          /// Default constructor
MoonPosition()88       MoonPosition() throw() {}
89 
90          /// Destructor
~MoonPosition()91       virtual ~MoonPosition() {}
92 
93 
94          /** Returns the position of Moon ECEF coordinates (meters) at the
95           *  indicated time.
96           *
97           * @param[in]  t the time to look up
98           *
99           * @return the position of the Moon at time (as a Triple)
100           *
101           * @throw InvalidRequest If the request can not be completed for any
102           *    reason, this is thrown. The text may have additional
103           *    information as to why the request failed.
104           *
105           * @warning This method yields and approximate result, given
106           *    that pole movement is not taken into account, neither
107           *    precession nor nutation.
108           */
109       Triple getPosition(const CommonTime& t) const;
110 
111 
112          /** Function to compute Moon position in CIS system (coordinates
113           *  in meters)
114           *
115           * @param t Epoch
116           */
117       Triple getPositionCIS(const CommonTime& t) const;
118 
119 
120          /** Determine the earliest time for which this object can
121           *  successfully determine the position for the Moon.
122           *
123           * @return The initial time
124           *
125           * @throw InvalidRequest This is thrown if the object has no data.
126           */
getInitialTime() const127       CommonTime getInitialTime() const
128       { return initialTime; }
129 
130 
131          /** Determine the latest time for which this object can
132           *  successfully determine the position for the Moon.
133           *
134           * @return The final time
135           *
136           * @throw InvalidRequest This is thrown if the object has no data.
137           */
getFinalTime() const138       CommonTime getFinalTime() const
139       { return finalTime; }
140 
141 
142    private:
143 
144          /// Time of the first valid time
145       static const CommonTime initialTime;
146 
147          /// Time of the last valid time
148       static const CommonTime finalTime;
149 
150          // Coefficients for fundamental arguments
151          // Units are degrees for position and Julian centuries for time
152 
153          /// Moon's mean longitude
154       static const double ELP0, ELP1, ELP2, ELP3;
155 
156          /// Sun's mean anomaly
157       static const double EM0, EM1, EM2, EM3;
158 
159          /// Moon's mean anomaly
160       static const double EMP0, EMP1, EMP2, EMP3;
161 
162          /// Moon's mean elongation
163       static const double D0, D1, D2, D3;
164 
165          /// Mean distance of the Moon from its ascending node
166       static const double F0, F1, F2, F3;
167 
168          /// Longitude of the Moon's ascending node
169       static const double OM0, OM1, OM2, OM3;
170 
171          /// Coefficients for (dimensionless) E factor
172       static const double E1, E2;
173 
174          /// Coefficients for periodic variations, etc
175       static const double PAC, PA0, PA1;
176       static const double PBC;
177       static const double PCC;
178       static const double PDC;
179       static const double PEC, PE0, PE1, PE2;
180       static const double PFC;
181       static const double PGC;
182       static const double PHC;
183       static const double cPIC;
184       static const double PJC, PJ0, PJ1;
185       static const double CW1;
186       static const double CW2;
187 
188          // Coefficients for Moon position
189          //      Tx(N): coefficient of L, B or P term (deg)
190          //      ITx(N,0-4): coefficients of M, M', D, F, E**n in argument
191          //
192       static const size_t NL, NB, NP;
193       static Vector<double> TL, TB, TP;
194       static Matrix<int> ITL, ITB, ITP;
195 
196    }; // end class MoonPosition
197 
198 
199       //@}
200 
201 } // namespace gpstk
202 #endif  // MOONPOSITION_HPP
203