Stellarium 0.12.3
StelUtils.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2002 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELUTILS_HPP_
21 #define _STELUTILS_HPP_
22 
23 #include "VecMath.hpp"
24 
25 #include <QVariantMap>
26 #include <QDateTime>
27 #include <QSize>
28 #include <QString>
29 
30 // astonomical unit (km)
31 #define AU 149597870.691
32 // Parsec (km)
33 #define PARSEC 30.857e12
34 // speed of light (km/sec)
35 #define SPEED_OF_LIGHT 299792.458
36 
38 namespace StelUtils
39 {
41  QString getApplicationName();
42 
44  QString getApplicationVersion();
45 
51  double hmsToRad(const unsigned int h, const unsigned int m, const double s);
52 
58  double dmsToRad(const int d, const unsigned int m, const double s);
59 
65  void radToHms(double rad, unsigned int& h, unsigned int& m, double& s);
66 
73  void radToDms(double rad, bool& sign, unsigned int& d, unsigned int& m, double& s);
74 
78  QString radToHmsStrAdapt(const double angle);
79 
83  QString radToHmsStr(const double angle, const bool decimal=false);
84 
89  QString radToDmsStrAdapt(const double angle, const bool useD=false);
90 
95  QString radToDmsStr(const double angle, const bool decimal=false, const bool useD=false);
96 
99  double dmsStrToRad(const QString& s);
100 
105  Vec3f strToVec3f(const QStringList& s);
106  Vec3f strToVec3f(const QString& s);
107 
111  QString vec3fToHtmlColor(const Vec3f& v);
112 
115  Vec3f htmlColorToVec3f(const QString& c);
116 
121  void spheToRect(const double lng, const double lat, Vec3d& v);
122 
127  void spheToRect(const float lng, const float lat, Vec3f& v);
128 
133  void rectToSphe(double *lng, double *lat, const Vec3d& v);
134 
139  void rectToSphe(float *lng, float *lat, const Vec3d& v);
140 
145  void rectToSphe(float *lng, float *lat, const Vec3f& v);
146 
147  // GZ: some additions. I need those just for quick conversions for text display.
149  void ctRadec2Ecl(const double raRad, const double decRad, const double eclRad, double *lambdaRad, double *betaRad);
150  // GZ: done
151 
172  double getDecAngle(const QString& str);
173 
175  bool isPowerOfTwo(const int value);
176 
178  int smallestPowerOfTwoGreaterOrEqualTo(const int value);
179 
181  QSize smallestPowerOfTwoSizeGreaterOrEqualTo(const QSize base);
182 
184  double asinh(const double z);
185 
187  // New Qt based General Calendar Functions.
189  void getDateFromJulianDay(const double julianDay, int *year, int *month, int *day);
190 
192  void getTimeFromJulianDay(const double julianDay, int *hour, int *minute, int *second);
193 
196  bool getDateTimeFromISO8601String(const QString& iso8601Date, int* y, int* m, int* d, int* h, int* min, float* s);
197 
200  QString julianDayToISO8601String(const double jd);
201 
204  double getJulianDayFromISO8601String(const QString& iso8601Date, bool* ok);
205 
210  QString localeDateString(const int year, const int month, const int day, const int dayOfWeek, const QString fmt);
211 
215  QString localeDateString(const int year, const int month, const int day, const int dayOfWeek);
216 
219  double getJDFromSystem();
220 
224  double qTimeToJDFraction(const QTime& time);
225 
227  QTime jdFractionToQTime(const double jd);
228 
230  float getGMTShiftFromQT(const double jd);
231 
235  double qDateTimeToJd(const QDateTime& dateTime);
236 
240  QDateTime jdToQDateTime(const double& jd);
241 
253  bool getJDFromDate(double* newjd, const int y, const int m, const int d, const int h, const int min, const int s);
254 
255  int numberOfDaysInMonthInYear(const int month, const int year);
256  bool changeDateTimeForRollover(int oy, int om, int od, int oh, int omin, int os,
257  int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
258 
260  void debugQVariantMap(const QVariant& m, const QString& indent="", const QString& key="");
261 
262 
265  inline float fastAcos(const float x)
266  {
267  return M_PI_2 - (x + x*x*x * (1.f/6.f + x*x * (3.f/40.f + 5.f/112.f * x*x)) );
268  }
269 
271  inline float fastExp(const float x)
272  {
273  return (x>=0)?
274  (1.f + x*(1.f+ x/2.f*(1.f+ x/3.f*(1.f+x/4.f*(1.f+x/5.f))))):
275  1.f / (1.f -x*(1.f -x/2.f*(1.f- x/3.f*(1.f-x/4.f*(1.f-x/5.f)))));
276  }
277 
280  inline Vec3f getNightColor(const Vec3f& dayColor)
281  {
282  float max = 0.0;
283  for(int i=0; i<3; i++)
284  {
285  max = dayColor[i] > max ? dayColor[i] : max;
286  }
287  return Vec3f(max, 0, 0);
288  }
289 
291  double calculateSiderealPeriod(const double SemiMajorAxis);
292 
293  QString hoursToHmsStr(const double hours);
294 
302  long double secondsSinceStart();
303 
307  // GZ: I don't see this returning 0. There is always a rough estimate beyond that.
311  double getDeltaTByEspenakMeeus(const double jDay);
312 
321  double getDeltaTBySchoch(const double jDay);
322 
332  double getDeltaTByClemence(const double jDay);
333 
342  double getDeltaTByIAU(const double jDay);
343 
353  double getDeltaTByAstronomicalEphemeris(const double jDay);
354 
359  double getDeltaTByTuckermanGoldstine(const double jDay);
360 
372  double getDeltaTByMullerStephenson(const double jDay);
373 
383  double getDeltaTByStephenson1978(const double jDay);
384 
391  double getDeltaTByStephenson1997(const double jDay);
392 
402  double getDeltaTBySchmadelZech1979(const double jDay);
403 
408  double getDeltaTByMorrisonStephenson1982(const double jDay);
409 
418  double getDeltaTByStephensonMorrison1984(const double jDay);
419 
428  double getDeltaTByStephensonMorrison1995(const double jDay);
429 
434  double getDeltaTByStephensonHoulden(const double jDay);
435 
441  double getDeltaTByEspenak(const double jDay);
442 
451  double getDeltaTByBorkowski(const double jDay);
452 
461  double getDeltaTBySchmadelZech1988(const double jDay);
462 
467  double getDeltaTByChaprontTouze(const double jDay);
468 
473  double getDeltaTByJPLHorizons(const double jDay);
474 
487  double getDeltaTByMorrisonStephenson2004(const double jDay);
488 
494  double getDeltaTByReijs(const double jDay);
495 
500  double getDeltaTByChaprontMeeus(const double jDay);
501 
510  double getDeltaTByMeeusSimons(const double jDay);
511 
518  double getDeltaTByMontenbruckPfleger(const double jDay);
519 
526  double getDeltaTByReingoldDershowitz(const double jDay);
527 
536  double getDeltaTByBanjevic(const double jDay);
537 
550  double getDeltaTByIslamSadiqQureshi(const double jDay);
551 
560  double getMoonSecularAcceleration(const double jDay, const double ndot);
561 
565  double getDeltaTStandardError(const double jDay);
566 }
567 
568 #endif // _STELUTILS_HPP_