Stellarium 0.13.0
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 "config.h"
24 
25 #include "VecMath.hpp"
26 
27 #include <QVariantMap>
28 #include <QDateTime>
29 #include <QString>
30 
31 // astronomical unit (km)
32 #define AU 149597870.691
33 #define AU_KM (1.0/149597870.691)
34 // Parsec (km)
35 #define PARSEC 30.857e12
36 // speed of light (km/sec)
37 #define SPEED_OF_LIGHT 299792.458
38 
40 namespace StelUtils
41 {
43  QString getApplicationName();
44 
46  QString getApplicationVersion();
47 
49  QString getOperatingSystemInfo();
50 
56  double hmsToRad(const unsigned int h, const unsigned int m, const double s);
57 
63  double dmsToRad(const int d, const unsigned int m, const double s);
64 
70  void radToHms(double rad, unsigned int& h, unsigned int& m, double& s);
71 
78  void radToDms(double rad, bool& sign, unsigned int& d, unsigned int& m, double& s);
79 
83  QString radToHmsStrAdapt(const double angle);
84 
88  QString radToHmsStr(const double angle, const bool decimal=false);
89 
94  QString radToDmsStrAdapt(const double angle, const bool useD=false);
95 
100  QString radToDmsStr(const double angle, const bool decimal=false, const bool useD=false);
101 
104  double dmsStrToRad(const QString& s);
105 
110  Vec3f strToVec3f(const QStringList& s);
111  Vec3f strToVec3f(const QString& s);
112 
116  QString vec3fToHtmlColor(const Vec3f& v);
117 
120  Vec3f htmlColorToVec3f(const QString& c);
121 
126  void spheToRect(const double lng, const double lat, Vec3d& v);
127 
132  void spheToRect(const float lng, const float lat, Vec3f& v);
133 
138  void rectToSphe(double *lng, double *lat, const Vec3d& v);
139 
144  void rectToSphe(float *lng, float *lat, const Vec3d& v);
145 
150  void rectToSphe(float *lng, float *lat, const Vec3f& v);
151 
152  // GZ: some additions. I need those just for quick conversions for text display.
154  void ctRadec2Ecl(const double raRad, const double decRad, const double eclRad, double *lambdaRad, double *betaRad);
155  // GZ: done
156 
177  double getDecAngle(const QString& str);
178 
180  bool isPowerOfTwo(const int value);
181 
183  int getBiggerEqualPowerOfTwo(int value);
184 
186  double asinh(const double z);
187 
189  // New Qt based General Calendar Functions.
191  void getDateFromJulianDay(const double julianDay, int *year, int *month, int *day);
192 
194  void getTimeFromJulianDay(const double julianDay, int *hour, int *minute, int *second);
195 
198  bool getDateTimeFromISO8601String(const QString& iso8601Date, int* y, int* m, int* d, int* h, int* min, float* s);
199 
202  QString julianDayToISO8601String(const double jd);
203 
206  double getJulianDayFromISO8601String(const QString& iso8601Date, bool* ok);
207 
212  QString localeDateString(const int year, const int month, const int day, const int dayOfWeek, const QString fmt);
213 
217  QString localeDateString(const int year, const int month, const int day, const int dayOfWeek);
218 
221  double getJDFromSystem();
222 
226  double qTimeToJDFraction(const QTime& time);
227 
229  QTime jdFractionToQTime(const double jd);
230 
232  float getGMTShiftFromQT(const double jd);
233 
237  double qDateTimeToJd(const QDateTime& dateTime);
238 
242  QDateTime jdToQDateTime(const double& jd);
243 
255  bool getJDFromDate(double* newjd, const int y, const int m, const int d, const int h, const int min, const int s);
256 
257  int numberOfDaysInMonthInYear(const int month, const int year);
258  bool changeDateTimeForRollover(int oy, int om, int od, int oh, int omin, int os,
259  int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
260 
262  void debugQVariantMap(const QVariant& m, const QString& indent="", const QString& key="");
263 
264 
267  inline float fastAcos(const float x)
268  {
269  return static_cast<float>(M_PI_2) - (x + x*x*x * (1.f/6.f + x*x * (3.f/40.f + 5.f/112.f * x*x)) );
270  }
271 
273  inline float fastExp(const float x)
274  {
275  return (x>=0)?
276  (1.f + x*(1.f+ x/2.f*(1.f+ x/3.f*(1.f+x/4.f*(1.f+x/5.f))))):
277  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)))));
278  }
279 
282  inline Vec3f getNightColor(const Vec3f& dayColor)
283  {
284  float max = 0.0;
285  for(int i=0; i<3; i++)
286  {
287  max = dayColor[i] > max ? dayColor[i] : max;
288  }
289  return Vec3f(max, 0, 0);
290  }
291 
293  double calculateSiderealPeriod(const double SemiMajorAxis);
294 
295  QString hoursToHmsStr(const double hours);
296 
304  long double secondsSinceStart();
305 
309  // GZ: I don't see this returning 0. There is always a rough estimate beyond that.
313  double getDeltaTByEspenakMeeus(const double jDay);
314 
323  double getDeltaTBySchoch(const double jDay);
324 
334  double getDeltaTByClemence(const double jDay);
335 
344  double getDeltaTByIAU(const double jDay);
345 
355  double getDeltaTByAstronomicalEphemeris(const double jDay);
356 
361  double getDeltaTByTuckermanGoldstine(const double jDay);
362 
374  double getDeltaTByMullerStephenson(const double jDay);
375 
385  double getDeltaTByStephenson1978(const double jDay);
386 
393  double getDeltaTByStephenson1997(const double jDay);
394 
404  double getDeltaTBySchmadelZech1979(const double jDay);
405 
410  double getDeltaTByMorrisonStephenson1982(const double jDay);
411 
420  double getDeltaTByStephensonMorrison1984(const double jDay);
421 
430  double getDeltaTByStephensonMorrison1995(const double jDay);
431 
436  double getDeltaTByStephensonHoulden(const double jDay);
437 
443  double getDeltaTByEspenak(const double jDay);
444 
453  double getDeltaTByBorkowski(const double jDay);
454 
463  double getDeltaTBySchmadelZech1988(const double jDay);
464 
469  double getDeltaTByChaprontTouze(const double jDay);
470 
475  double getDeltaTByJPLHorizons(const double jDay);
476 
489  double getDeltaTByMorrisonStephenson2004(const double jDay);
490 
496  double getDeltaTByReijs(const double jDay);
497 
502  double getDeltaTByChaprontMeeus(const double jDay);
503 
512  double getDeltaTByMeeusSimons(const double jDay);
513 
520  double getDeltaTByMontenbruckPfleger(const double jDay);
521 
528  double getDeltaTByReingoldDershowitz(const double jDay);
529 
538  double getDeltaTByBanjevic(const double jDay);
539 
552  double getDeltaTByIslamSadiqQureshi(const double jDay);
553 
562  double getMoonSecularAcceleration(const double jDay, const double ndot);
563 
567  double getDeltaTStandardError(const double jDay);
568 
570  template <typename T> int sign(T val) {
571  return (T(0) < val) - (val < T(0));
572  }
573 }
574 
575 #endif // _STELUTILS_HPP_
double getDeltaTByMontenbruckPfleger(const double jDay)
Get Delta-T estimation for a given date.
bool getDateTimeFromISO8601String(const QString &iso8601Date, int *y, int *m, int *d, int *h, int *min, float *s)
Parse an ISO8601 date string.
bool isPowerOfTwo(const int value)
Check if a number is a power of 2.
QTime jdFractionToQTime(const double jd)
Convert a fraction of a Julian Day to a QTime.
double getDeltaTByMorrisonStephenson2004(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByIslamSadiqQureshi(const double jDay)
Get Delta-T estimation for a given date.
double getJDFromSystem()
Get the current Julian Date from system time.
double getDeltaTByJPLHorizons(const double jDay)
Get Delta-T estimation for a given date.
void rectToSphe(double *lng, double *lat, const Vec3d &v)
Convert from spherical coordinates to Rectangular direction.
int getBiggerEqualPowerOfTwo(int value)
Return the first power of two bigger or equal to the given value.
double getDeltaTByReijs(const double jDay)
Get Delta-T estimation for a given date.
Vec3f strToVec3f(const QStringList &s)
Obtains a Vec3f from a string.
QString getApplicationName()
Return the full name of stellarium, i.e. "stellarium 0.9.0".
double dmsStrToRad(const QString &s)
Convert a dms formatted string to an angle in radian.
void spheToRect(const double lng, const double lat, Vec3d &v)
Convert from spherical coordinates to Rectangular direction.
void getTimeFromJulianDay(const double julianDay, int *hour, int *minute, int *second)
Make from julianDay an hour, minute, second.
double hmsToRad(const unsigned int h, const unsigned int m, const double s)
Convert an angle in hms format to radian.
double getDeltaTByEspenak(const double jDay)
Get Delta-T estimation for a given date.
QString getOperatingSystemInfo()
Return the name and the version of operating system, i.e. "Mac OS X 10.7".
QString radToHmsStrAdapt(const double angle)
Convert an angle in radian to a hms formatted string.
QString vec3fToHtmlColor(const Vec3f &v)
Converts a Vec3f to HTML color notation.
double getDeltaTByBanjevic(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByChaprontTouze(const double jDay)
Get Delta-T estimation for a given date.
QDateTime jdToQDateTime(const double &jd)
Convert a julian day to a QDateTime.
Vec3f getNightColor(const Vec3f &dayColor)
Get a night mode version of a color.
Definition: StelUtils.hpp:282
double qDateTimeToJd(const QDateTime &dateTime)
Convert a QT QDateTime class to julian day.
void radToHms(double rad, unsigned int &h, unsigned int &m, double &s)
Convert an angle in radian to hms format.
double getDeltaTByMorrisonStephenson1982(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByTuckermanGoldstine(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByBorkowski(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTBySchmadelZech1988(const double jDay)
Get Delta-T estimation for a given date.
QString getApplicationVersion()
Return the version of stellarium, i.e. "0.9.0".
QString julianDayToISO8601String(const double jd)
Format the given Julian Day in (UTC) ISO8601 date string.
double getDeltaTByChaprontMeeus(const double jDay)
Get Delta-T estimation for a given date.
float fastAcos(const float x)
Compute acos(x) The taylor serie is not accurate around x=1 and x=-1.
Definition: StelUtils.hpp:267
void ctRadec2Ecl(const double raRad, const double decRad, const double eclRad, double *lambdaRad, double *betaRad)
Coordinate Transformation from equatorial to ecliptical.
double getDeltaTBySchoch(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByStephensonMorrison1984(const double jDay)
Get Delta-T estimation for a given date.
QString radToDmsStr(const double angle, const bool decimal=false, const bool useD=false)
Convert an angle in radian to a dms formatted string.
double getDeltaTBySchmadelZech1979(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByIAU(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByEspenakMeeus(const double jDay)
Get Delta-T estimation for a given date.
void radToDms(double rad, bool &sign, unsigned int &d, unsigned int &m, double &s)
Convert an angle in radian to +-dms format.
double dmsToRad(const int d, const unsigned int m, const double s)
Convert an angle in +-dms format to radian.
double calculateSiderealPeriod(const double SemiMajorAxis)
Calculate and getting sidereal period in days from semi-major axis (in AU)
QString localeDateString(const int year, const int month, const int day, const int dayOfWeek, const QString fmt)
Format the date and day-of-week per the format in fmt (see QDateTime::toString()).
double getMoonSecularAcceleration(const double jDay, const double ndot)
Get Secular Acceleration estimation for a given year.
double getDeltaTByStephenson1997(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByStephenson1978(const double jDay)
Get Delta-T estimation for a given date.
QString radToDmsStrAdapt(const double angle, const bool useD=false)
Convert an angle in radian to a dms formatted string.
double getDeltaTByAstronomicalEphemeris(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByClemence(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByMeeusSimons(const double jDay)
Get Delta-T estimation for a given date.
double getDecAngle(const QString &str)
Convert a string longitude, latitude, RA or Declination angle to radians.
long double secondsSinceStart()
Get the number of seconds since program start.
double getDeltaTByMullerStephenson(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByStephensonMorrison1995(const double jDay)
Get Delta-T estimation for a given date.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
QString radToHmsStr(const double angle, const bool decimal=false)
Convert an angle in radian to a hms formatted string.
double getJulianDayFromISO8601String(const QString &iso8601Date, bool *ok)
Return the Julian Date matching the ISO8601 date string.
int sign(T val)
Sign function from http://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signu...
Definition: StelUtils.hpp:570
double qTimeToJDFraction(const QTime &time)
Convert a time of day to the fraction of a Julian Day.
bool getJDFromDate(double *newjd, const int y, const int m, const int d, const int h, const int min, const int s)
Compute Julian day number from calendar date.
void getDateFromJulianDay(const double julianDay, int *year, int *month, int *day)
Make from julianDay a year, month, day for the Julian Date julianDay represents.
double getDeltaTStandardError(const double jDay)
Get the standard error (sigma) for the value of DeltaT.
double getDeltaTByReingoldDershowitz(const double jDay)
Get Delta-T estimation for a given date.
double getDeltaTByStephensonHoulden(const double jDay)
Get Delta-T estimation for a given date.
float fastExp(const float x)
Compute exp(x) for small exponents x.
Definition: StelUtils.hpp:273
Vec3f htmlColorToVec3f(const QString &c)
Converts a color in HTML notation to a Vec3f.
double asinh(const double z)
Return the inverse sinus hyperbolic of z.
float getGMTShiftFromQT(const double jd)
Return number of hours offset from GMT, using Qt functions.
void debugQVariantMap(const QVariant &m, const QString &indent="", const QString &key="")
Output a QVariantMap to qDebug(). Formats like a tree where there are nested objects.