• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • edu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • extragear
  • edu
  • kstars
  • kstars
ksalmanac.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksalmanac.cpp - description
3 
4  -------------------
5  begin : Friday May 8, 2009
6  copyright : (C) 2009 by Prakash Mohan
7  email : [email protected]
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "ksalmanac.h"
20 
21 #include "geolocation.h"
22 #include "ksnumbers.h"
23 #include "kstarsdata.h"
24 
25 KSAlmanac::KSAlmanac()
26 {
27  KStarsData *data = KStarsData::Instance();
28 
29  /*dt = KStarsDateTime::currentDateTime();
30  geo = data->geo();
31  dt.setTime(QTime());
32  dt = geo->LTtoUT(dt);*/
33 
34  // Jasem 2015-08-24 Do NOT use KStarsDataTime for local time, it is only for UTC
35  QDateTime midnight = QDateTime(data->lt().date(), QTime());
36  geo = data->geo();
37  dt = geo->LTtoUT(KStarsDateTime(midnight));
38  update();
39 }
40 
41 void KSAlmanac::update()
42 {
43  RiseSetTime(&m_Sun, &SunRise, &SunSet, &SunRiseT, &SunSetT);
44  RiseSetTime(&m_Moon, &MoonRise, &MoonSet, &MoonRiseT, &MoonSetT);
45  // qDebug() << "Sun rise: " << SunRiseT.toString() << " Sun set: " << SunSetT.toString() << " Moon rise: " << MoonRiseT.toString() << " Moon set: " << MoonSetT.toString();
46  findDawnDusk();
47  findMoonPhase();
48 }
49 
50 void KSAlmanac::RiseSetTime(SkyObject *o, double *riseTime, double *setTime, QTime *RiseTime, QTime *SetTime)
51 {
52  // Compute object rise and set times
53  const KStarsDateTime today = dt;
54  const GeoLocation *_geo = geo;
55  *RiseTime = o->riseSetTime(
56  today, _geo,
57  true); // FIXME: Should we add a day here so that we report future rise time? Not doing so produces the right results for the moon. Not sure about the sun.
58  *SetTime = o->riseSetTime(today, _geo, false);
59  *riseTime = -1.0 * RiseTime->secsTo(QTime(0, 0, 0, 0)) / 86400.0;
60  *setTime = -1.0 * SetTime->secsTo(QTime(0, 0, 0, 0)) / 86400.0;
61 
62  // Check to see if the object is circumpolar
63  // NOTE: Since we are working on a local copy of the Sun / Moon,
64  // we freely change the geolocation / time without setting
65  // them back.
66 
67  KSNumbers num(dt.djd());
68  CachingDms LST = geo->GSTtoLST(dt.gst());
69  o->updateCoords(&num, true, geo->lat(), &LST, true);
70  if (o->checkCircumpolar(geo->lat()))
71  {
72  if (o->alt().Degrees() > 0.0)
73  {
74  //Circumpolar, signal it this way:
75  *riseTime = 0.0;
76  *setTime = 1.0;
77  }
78  else
79  {
80  //never rises, signal it this way:
81  *riseTime = 0.0;
82  *setTime = -1.0;
83  }
84  }
85 }
86 
87 // FIXME: This is utter code duplication. All this should be handled
88 // in the KStars engine. Forgive me for adding to the nonsense, but I
89 // want to get the Observation Planner functional first. -- asimha
90 // seems to be copied from AltVsTime::setDawnDusk
91 void KSAlmanac::findDawnDusk()
92 {
93  KStarsDateTime today = dt;
94  KSNumbers num(today.djd());
95  CachingDms LST = geo->GSTtoLST(today.gst());
96 
97  m_Sun.updateCoords(&num, true, geo->lat(), &LST, true); // We can abuse our own copy of the sun
98  double dawn, da, dusk, du, max_alt, min_alt;
99  double last_h = -12.0;
100  double last_alt = findAltitude(&m_Sun, last_h);
101  dawn = dusk = -13.0;
102  max_alt = -100.0;
103  min_alt = 100.0;
104  for (double h = -11.95; h <= 12.0; h += 0.05)
105  {
106  double alt = findAltitude(&m_Sun, h);
107  bool asc = alt - last_alt > 0;
108  if (alt > max_alt)
109  max_alt = alt;
110  if (alt < min_alt)
111  min_alt = alt;
112 
113  if (asc && last_alt <= -18.0 && alt >= -18.0)
114  dawn = h;
115  if (!asc && last_alt >= -18.0 && alt <= -18.0)
116  dusk = h;
117 
118  // Never used
119 // last_h = h;
120  last_alt = alt;
121  }
122 
123  if (dawn < -12.0 || dusk < -12.0)
124  {
125  da = -1.0;
126  du = -1.0;
127  }
128  else
129  {
130  da = dawn / 24.0;
131  du = (dusk + 24.0) / 24.0;
132  }
133 
134  DawnAstronomicalTwilight = da;
135  DuskAstronomicalTwilight = du;
136 
137  SunMaxAlt = max_alt;
138  SunMinAlt = min_alt;
139 }
140 
141 void KSAlmanac::findMoonPhase()
142 {
143  const KStarsDateTime today = dt;
144  KSNumbers num(today.djd());
145  CachingDms LST = geo->GSTtoLST(today.gst());
146 
147  m_Sun.updateCoords(&num, true, geo->lat(), &LST, true); // We can abuse our own copy of the sun and/or moon
148  m_Moon.updateCoords(&num, true, geo->lat(), &LST, true);
149  m_Moon.findPhase(&m_Sun);
150  MoonPhase = m_Moon.phase().Degrees();
151 }
152 
153 void KSAlmanac::setDate(const KStarsDateTime *newdt)
154 {
155  dt = *newdt;
156  update();
157 }
158 
159 void KSAlmanac::setLocation(const GeoLocation *geo_)
160 {
161  geo = geo_;
162  update();
163 }
164 
165 double KSAlmanac::sunZenithAngleToTime(double z)
166 {
167  // TODO: Correct for movement of the sun
168  double HA = acos((cos(z * dms::DegToRad) - m_Sun.dec().sin() * geo->lat()->sin()) /
169  (m_Sun.dec().cos() * geo->lat()->cos()));
170  double HASunset = acos((-m_Sun.dec().sin() * geo->lat()->sin()) / (m_Sun.dec().cos() * geo->lat()->cos()));
171  return SunSet + (HA - HASunset) / 24.0;
172 }
173 
174 double KSAlmanac::findAltitude(const SkyPoint *p, double hour)
175 {
176  return SkyPoint::findAltitude(p, dt, geo, hour).Degrees();
177 }
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:78
CachingDms::sin
double sin() const
Get the sine of this angle.
Definition: cachingdms.h:201
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:98
dms::Degrees
const double & Degrees() const
Definition: dms.h:152
KSMoon::findPhase
void findPhase(const KSSun *Sun=nullptr)
Determine the phase angle of the moon, and assign the appropriate moon image.
Definition: ksmoon.cpp:276
SkyPoint::findAltitude
static dms findAltitude(const SkyPoint *p, const KStarsDateTime &dt, const GeoLocation *geo, const double hour=0)
Compute the altitude of a given skypoint hour hours from the given date/time.
Definition: skypoint.cpp:899
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:215
KSAlmanac::KSAlmanac
KSAlmanac()
Definition: ksalmanac.cpp:25
QTime
KSAlmanac::setDate
void setDate(const KStarsDateTime *newdt)
Set the date for computations to the given date.
Definition: ksalmanac.cpp:153
GeoLocation::lat
const CachingDms * lat() const
Definition: geolocation.h:82
geolocation.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:56
SkyObject::riseSetTime
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true) const
Determine the time at which the point will rise or set.
Definition: skyobject.cpp:109
KStarsData::lt
const KStarsDateTime & lt() const
Definition: kstarsdata.h:158
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
GeoLocation::GSTtoLST
dms GSTtoLST(const dms &gst) const
Definition: geolocation.h:308
KSAlmanac::setLocation
void setLocation(const GeoLocation *geo_)
Set the location for computations to the given location.
Definition: ksalmanac.cpp:159
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:169
SkyPoint::updateCoords
virtual void updateCoords(const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0), accounting for both precession and nutation.
Definition: skypoint.cpp:411
KStarsDateTime
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:46
ksnumbers.h
SkyPoint::dec
const CachingDms & dec() const
Definition: skypoint.h:209
dms::DegToRad
static constexpr double DegToRad
DegToRad is a const static member equal to the number of radians in one degree (dms::PI/180.0).
Definition: dms.h:390
KSAlmanac::sunZenithAngleToTime
double sunZenithAngleToTime(double z)
Convert the zenithal distance of the sun to fraction of the day.
Definition: ksalmanac.cpp:165
SkyPoint::checkCircumpolar
bool checkCircumpolar(const dms *gLat) const
Check if this point is circumpolar at the given geographic latitude.
Definition: skypoint.cpp:849
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:54
ksalmanac.h
QDateTime::date
QDate date() const
CachingDms::cos
double cos() const
Get the cosine of this angle.
Definition: cachingdms.h:215
kstarsdata.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:215
KSPlanetBase::updateCoords
void updateCoords(const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, bool forceRecompute=false) override
Update position of the planet (reimplemented from SkyPoint)
Definition: ksplanetbase.cpp:97
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:172
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:43
QTime::secsTo
int secsTo(const QTime &t) const
CachingDms
a dms subclass that caches its sine and cosine values every time the angle is changed.
Definition: cachingdms.h:29
QDateTime
KSPlanetBase::phase
dms phase()
Definition: ksplanetbase.h:211
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Dec 9 2019 02:11:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

edu API Reference

Skip menu "edu API Reference"
  •     core
  • kstars

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal