calc.h
/*
*openPilotLog - A FOSS Pilot Logbook Application
*Copyright (C) 2020-2022 Felix Turowsky
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CALC_H
#define CALC_H
#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#include <QDateTime>
#include <QDebug>
#include "src/functions/time.h"
namespace OPL::Calc {
inline double radToDeg(double rad)
{
double deg = rad * (180 / M_PI);
return deg;
}
inline double degToRad(double deg)
{
double rad = deg * (M_PI / 180);
return rad;
}
inline double radToNauticalMiles(double rad)
{
double nm = rad * 3440.06479482;
return nm;
}
double greatCircleDistance(double lat1, double lon1, double lat2, double lon2);
double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest);
QVector<QVector<double>> intermediatePointsOnGreatCircle(double lat1,
double lon1,
double lat2,
double lon2,
int tblk);
double solarElevation(QDateTime utc_time_point, double lat, double lon);
int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle);
bool isNight(const QString &icao, QDateTime event_time, int night_angle);
QString formatTimeInput(QString user_input);
void updateAutoTimes(int acft_id);
void updateNightTimes();
struct NightTimeValues{
NightTimeValues() = delete;
NightTimeValues(const QString& dept, const QString& dest, const QDateTime& departure_time, int block_minutes, int night_angle)
{
nightMinutes = calculateNightTime(dept, dest, departure_time, block_minutes, night_angle);
nightTime = OPL::Time::qTimefromMinutes(nightMinutes);
totalTime = OPL::Time::qTimefromMinutes(block_minutes);
if (nightMinutes == 0) { // all day
takeOffNight = false;
landingNight = false;
}
else if (nightMinutes == block_minutes) { // all night
takeOffNight = true;
landingNight = true;
} else {
if(isNight(dept, departure_time, night_angle))
takeOffNight = true;
else
takeOffNight = false;
if(isNight(dest, departure_time.addSecs(block_minutes * 60), night_angle))
landingNight = true;
else
landingNight = false;
}
};
NightTimeValues(bool to_night, bool ldg_night, int night_minutes, QTime night_time, QTime total_time)
: takeOffNight(to_night), landingNight(ldg_night), nightMinutes(night_minutes), nightTime(night_time), totalTime(total_time){};
bool takeOffNight;
bool landingNight;
int nightMinutes;
QTime nightTime;
QTime totalTime;
inline bool isAllDay() {return (!takeOffNight && !landingNight);}
inline bool isAllNight() {return ( takeOffNight && landingNight);}
inline bool isDayToNight() {return (!takeOffNight && landingNight);}
inline bool isNightToDay() {return ( takeOffNight && !landingNight);}
};
} // namespace OPL::Calc
#endif // CALC_H
OPL::Calc
The ACalc namespace provides various functions for calculations that are performed outside of the dat...
Definition: calc.h:34
OPL::Calc::updateAutoTimes
void updateAutoTimes(int acft_id)
OPL::Calc::updateAutoTimes When the details of an aircraft are changed, this function recalculates de...
Definition: calc.cpp:301
OPL::Calc::greatCircleDistanceBetweenAirports
double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest)
Opl::Calc::greatCircleDistanceBetweenAirports Calculates Great Circle distance between two coordinate...
Definition: calc.cpp:103
OPL::Calc::calculateNightTime
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: calc.cpp:226
OPL::Calc::degToRad
double degToRad(double deg)
degToRad Converts degrees to radians
Definition: calc.h:52
OPL::Calc::updateNightTimes
void updateNightTimes()
OPL::Calc::updateNightTimes updates the night times in the database, used when changing night angle s...
Definition: calc.cpp:344
OPL::Calc::formatTimeInput
QString formatTimeInput(QString user_input)
OPL::Calc::formatTimeInput verifies user input and formats to hh:mm if the output is not a valid time...
Definition: calc.cpp:31
OPL::Calc::radToNauticalMiles
double radToNauticalMiles(double rad)
radToNauticalMiles Convert Radians to nautical miles
Definition: calc.h:63
OPL::Calc::intermediatePointsOnGreatCircle
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: calc.cpp:133
OPL::Calc::solarElevation
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: calc.cpp:167
OPL::Calc::radToDeg
double radToDeg(double rad)
radToDeg Converts radians to degrees
Definition: calc.h:41
OPL::Calc::greatCircleDistance
double greatCircleDistance(double lat1, double lon1, double lat2, double lon2)
greatCircleDistance Calculates Great Circle distance between two coordinates, return in Radians.
Definition: calc.cpp:84
OPL::Calc::NightTimeValues
The NightTimeValues struct encapsulates values relating to night time that are needed by the NewFligh...
Definition: calc.h:144