Sunset
sunset.h
1 /*
2  * Provides the ability to calculate the local time for sunrise,
3  * sunset, and moonrise at any point in time at any location in the world
4  *
5  * Original work used with permission maintaining license
6  * Copyright (GPL) 2004 Mike Chirico mchirico@comcast.net
7  * Modifications copyright
8  * Copyright (GPL) 2015 Peter Buelow
9  *
10  * This file is part of the Sunset library
11  *
12  * Sunset is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * Sunset is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef __SUNPOSITION_H__
27 #define __SUNPOSITION_H__
28 
29 #include <cmath>
30 #include <ctime>
31 
32 #ifndef M_PI
33  #define M_PI 3.14159265358979323846264338327950288
34 #endif
35 
66 class SunSet {
67 public:
68  SunSet();
69  SunSet(double, double, int);
70  SunSet(double, double, double);
71  ~SunSet();
72 
73  static constexpr double SUNSET_OFFICIAL = 90.833;
74  static constexpr double SUNSET_NAUTICAL = 102.0;
75  static constexpr double SUNSET_CIVIL = 96.0;
76  static constexpr double SUNSET_ASTONOMICAL = 108.0;
78  void setPosition(double, double, int);
79  void setPosition(double, double, double);
80  void setTZOffset(int);
81  void setTZOffset(double);
82  double setCurrentDate(int, int, int);
83  double calcNauticalSunrise() const;
84  double calcNauticalSunset() const;
85  double calcCivilSunrise() const;
86  double calcCivilSunset() const;
87  double calcAstronomicalSunrise() const;
88  double calcAstronomicalSunset() const;
89  double calcCustomSunrise(double) const;
90  double calcCustomSunset(double) const;
91  [[deprecated("UTC specific calls may not be supported in the future")]] double calcSunriseUTC();
92  [[deprecated("UTC specific calls may not be supported in the future")]] double calcSunsetUTC();
93  double calcSunrise() const;
94  double calcSunset() const;
95  int moonPhase(int) const;
96  int moonPhase() const;
97 
98 private:
99  double degToRad(double) const;
100  double radToDeg(double) const;
101  double calcMeanObliquityOfEcliptic(double) const;
102  double calcGeomMeanLongSun(double) const;
103  double calcObliquityCorrection(double) const;
104  double calcEccentricityEarthOrbit(double) const;
105  double calcGeomMeanAnomalySun(double) const;
106  double calcEquationOfTime(double) const;
107  double calcTimeJulianCent(double) const;
108  double calcSunTrueLong(double) const;
109  double calcSunApparentLong(double) const;
110  double calcSunDeclination(double) const;
111  double calcHourAngleSunrise(double, double, double) const;
112  double calcHourAngleSunset(double, double, double) const;
113  double calcJD(int,int,int) const;
114  double calcJDFromJulianCent(double) const;
115  double calcSunEqOfCenter(double) const;
116  double calcAbsSunrise(double) const;
117  double calcAbsSunset(double) const;
118 
119  double m_latitude;
120  double m_longitude;
121  double m_julianDate;
122  double m_tzOffset;
123  int m_year;
124  int m_month;
125  int m_day;
126 };
127 
128 #endif
Definition: sunset.h:66
double calcNauticalSunrise() const
Definition: sunset.cpp:433
double calcSunsetUTC()
Definition: sunset.cpp:378
static constexpr double SUNSET_NAUTICAL
Definition: sunset.h:74
double setCurrentDate(int, int, int)
Definition: sunset.cpp:508
void setPosition(double, double, int)
Definition: sunset.cpp:93
double calcNauticalSunset() const
Definition: sunset.cpp:444
double calcCivilSunrise() const
Definition: sunset.cpp:411
SunSet()
Definition: sunset.cpp:35
static constexpr double SUNSET_ASTONOMICAL
Definition: sunset.h:76
int moonPhase() const
Definition: sunset.cpp:582
double calcAstronomicalSunset() const
Definition: sunset.cpp:400
double calcCustomSunrise(double) const
Definition: sunset.cpp:479
double calcSunrise() const
Definition: sunset.cpp:455
double calcAstronomicalSunrise() const
Definition: sunset.cpp:389
~SunSet()
Definition: sunset.cpp:72
static constexpr double SUNSET_CIVIL
Definition: sunset.h:75
double calcSunset() const
Definition: sunset.cpp:466
void setTZOffset(int)
Definition: sunset.cpp:530
double calcCustomSunset(double) const
Definition: sunset.cpp:492
static constexpr double SUNSET_OFFICIAL
Definition: sunset.h:73
double calcSunriseUTC()
Definition: sunset.cpp:365
double calcCivilSunset() const
Definition: sunset.cpp:422