File indexing completed on 2024-05-19 05:37:53
0001 /* 0002 SPDX-FileCopyrightText: 2009 Petri Damsten <damu@iki.fi> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QDateTime> 0010 #include <QPair> 0011 #include <QPointF> 0012 0013 /* 0014 * Mathematics, ideas, public domain code used for these classes from: 0015 * https://www.stjarnhimlen.se/comp/tutorial.html 0016 * https://www.stjarnhimlen.se/comp/riset.html 0017 * https://www.esrl.noaa.gov/gmd/grad/solcalc/azel.html 0018 * https://www.esrl.noaa.gov/gmd/grad/solcalc/sunrise.html 0019 * http://web.archive.org/web/20080309162302/http://bodmas.org/astronomy/riset.html 0020 * moontool.c by John Walker 0021 * Wikipedia 0022 */ 0023 0024 class SolarSystemObject 0025 { 0026 public: 0027 SolarSystemObject(); 0028 virtual ~SolarSystemObject(); 0029 0030 double meanLongitude() const 0031 { 0032 return L; 0033 }; 0034 double meanAnomaly() const 0035 { 0036 return M; 0037 }; 0038 double siderealTime(); 0039 double altitude() const 0040 { 0041 return m_altitude; 0042 }; 0043 double azimuth() const 0044 { 0045 return m_azimuth; 0046 }; 0047 double calcElevation(); 0048 QDateTime dateTime() const 0049 { 0050 return m_local; 0051 }; 0052 double lambda() const 0053 { 0054 return m_lambda; 0055 }; 0056 double eclipticLongitude() const 0057 { 0058 return m_eclipticLongitude; 0059 }; 0060 void setPosition(double latitude, double longitude); 0061 0062 virtual void calcForDateTime(const QDateTime &local, int offset); 0063 QList<QPair<QDateTime, QDateTime>> timesForAngles(const QList<double> &angles, const QDateTime &dt, int offset); 0064 0065 protected: 0066 void calc(); 0067 virtual bool calcPerturbations(double *, double *, double *) 0068 { 0069 return false; 0070 }; 0071 virtual void rotate(double *, double *){}; 0072 virtual void topocentricCorrection(double *, double *){}; 0073 0074 inline double rev(double x); 0075 inline double asind(double x); 0076 inline double sind(double x); 0077 inline double cosd(double x); 0078 inline double atand(double x); 0079 inline double tand(double x); 0080 inline double atan2d(double y, double x); 0081 void toRectangular(double lo, double la, double r, double *x, double *y, double *z); 0082 void toSpherical(double x, double y, double z, double *lo, double *la, double *r); 0083 QPair<double, double> zeroPoints(QPointF p1, QPointF p2, QPointF p3); 0084 0085 double N; 0086 double i; 0087 double w; 0088 double a; 0089 double e; 0090 double M; 0091 double m_obliquity; 0092 0093 QDateTime m_utc; 0094 QDateTime m_local; 0095 double m_day; 0096 double m_latitude; 0097 double m_longitude; 0098 0099 double L; 0100 double rad; 0101 double RA; 0102 double dec; 0103 double HA; 0104 double m_altitude; 0105 double m_azimuth; 0106 double m_eclipticLongitude; 0107 double m_lambda; 0108 }; 0109 0110 class Sun : public SolarSystemObject 0111 { 0112 public: 0113 Sun(); 0114 void calcForDateTime(const QDateTime &local, int offset) override; 0115 0116 protected: 0117 void rotate(double *, double *) override; 0118 }; 0119 0120 class Moon : public SolarSystemObject 0121 { 0122 public: 0123 explicit Moon(Sun *sun); 0124 ~Moon() override{}; // to not delete the Sun 0125 0126 void calcForDateTime(const QDateTime &local, int offset) override; 0127 double phase(); 0128 0129 protected: 0130 bool calcPerturbations(double *RA, double *dec, double *r) override; 0131 void rotate(double *, double *) override; 0132 void topocentricCorrection(double *, double *) override; 0133 0134 private: 0135 Sun *m_sun; 0136 };