openPilotLog
acalc.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 Felix Turowsky
4  *
5  *This program is free software: you can redistribute it and/or modify
6  *it under the terms of the GNU General Public License as published by
7  *the Free Software Foundation, either version 3 of the License, or
8  *(at your option) any later version.
9  *
10  *This program 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 General Public License for more details.
14  *
15  *You should have received a copy of the GNU General Public License
16  *along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 #ifndef ACALC_H
19 #define ACALC_H
20 
21 #ifdef _MSC_VER
22 #define _USE_MATH_DEFINES
23 #endif
24 #include <cmath>
25 #include <QDateTime>
26 #include <QDebug>
27 #include "src/functions/alog.h"
28 #include "src/functions/atime.h"
35 namespace ACalc {
36 
42 inline double radToDeg(double rad)
43 {
44  double deg = rad * (180 / M_PI);
45  return deg;
46 }
47 
53 inline double degToRad(double deg)
54 {
55  double rad = deg * (M_PI / 180);
56  return rad;
57 }
58 
64 inline double radToNauticalMiles(double rad)
65 {
66  double nm = rad * 3440.06479482;
67  return nm;
68 }
69 
78 double greatCircleDistance(double lat1, double lon1, double lat2, double lon2);
79 
87 double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest);
88 
99 QVector<QVector<double>> intermediatePointsOnGreatCircle(double lat1,
100  double lon1,
101  double lat2,
102  double lon2,
103  int tblk);
120 double solarElevation(QDateTime utc_time_point, double lat, double lon);
121 
132 int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle);
133 
134 bool isNight(const QString &icao, QDateTime event_time, int night_angle);
135 
136 QString formatTimeInput(QString user_input);
137 
138 void updateAutoTimes(int acft_id);
139 
140 void updateNightTimes();
141 
146  NightTimeValues() = delete;
147  NightTimeValues(const QString& dept, const QString& dest, const QDateTime& departure_time, int block_minutes, int night_angle)
148  {
149  nightMinutes = calculateNightTime(dept, dest, departure_time, block_minutes, night_angle);
150 
151  nightTime = ATime::qTimefromMinutes(nightMinutes);
152  totalTime = ATime::qTimefromMinutes(block_minutes);
153 
154  if (nightMinutes == 0) { // all day
155  takeOffNight = false;
156  landingNight = false;
157  }
158  else if (nightMinutes == block_minutes) { // all night
159  takeOffNight = true;
160  landingNight = true;
161  } else {
162  if(isNight(dept, departure_time, night_angle))
163  takeOffNight = true;
164  else
165  takeOffNight = false;
166  if(isNight(dest, departure_time.addSecs(block_minutes * 60), night_angle))
167  landingNight = true;
168  else
169  landingNight = false;
170  }
171 
172  };
173  NightTimeValues(bool to_night, bool ldg_night, int night_minutes, QTime night_time, QTime total_time)
174  : takeOffNight(to_night), landingNight(ldg_night), nightMinutes(night_minutes), nightTime(night_time), totalTime(total_time){};
175  bool takeOffNight;
176  bool landingNight;
177  int nightMinutes;
178  QTime nightTime;
179  QTime totalTime;
180 
181  inline bool isAllDay() {return (!takeOffNight && !landingNight);}
182  inline bool isAllNight() {return ( takeOffNight && landingNight);}
183  inline bool isDayToNight() {return (!takeOffNight && landingNight);}
184  inline bool isNightToDay() {return ( takeOffNight && !landingNight);}
185 };
186 
187 
188 } // namespace ACalc
189 
190 #endif // ACALC_H
The ACalc namespace provides various functions for calculations that are performed outside of the dat...
Definition: acalc.h:35
double radToDeg(double rad)
radToDeg Converts radians to degrees
Definition: acalc.h:42
double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest)
ACalc::greatCircleDistanceBetweenAirports Calculates Great Circle distance between two coordinates,...
Definition: acalc.cpp:107
double radToNauticalMiles(double rad)
radToNauticalMiles Convert Radians to nautical miles
Definition: acalc.h:64
void updateAutoTimes(int acft_id)
ACalc::updateAutoTimes When the details of an aircraft are changed, this function recalculates deduct...
Definition: acalc.cpp:305
QVector< QVector< double > > intermediatePointsOnGreatCircle(double lat1, double lon1, double lat2, double lon2, int tblk)
Calculates a list of points (lat,lon) along the Great Circle between two points. The points are space...
Definition: acalc.cpp:137
int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle)
Calculates which portion of a flight was conducted in night conditions.
Definition: acalc.cpp:230
double greatCircleDistance(double lat1, double lon1, double lat2, double lon2)
greatCircleDistance Calculates Great Circle distance between two coordinates, return in Radians.
Definition: acalc.cpp:88
double degToRad(double deg)
degToRad Converts degrees to radians
Definition: acalc.h:53
double solarElevation(QDateTime utc_time_point, double lat, double lon)
Calculates solar elevation angle for a given point in time and latitude/longitude coordinates.
Definition: acalc.cpp:171
QString formatTimeInput(QString user_input)
ACalc::formatTimeInput verifies user input and formats to hh:mm if the output is not a valid time,...
Definition: acalc.cpp:35
void updateNightTimes()
ACalc::updateNightTimes updates the night times in the database, used when changing night angle setti...
Definition: acalc.cpp:348
The NightTimeValues struct encapsulates values relating to night time that are needed by the NewFligh...
Definition: acalc.h:145