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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • 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 : prakash.mohan@kdemail.net
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 <cmath>
22 
23 #include "geolocation.h"
24 #include "kstarsdata.h"
25 #include "kstarsdatetime.h"
26 #include "ksnumbers.h"
27 #include "dms.h"
28 #include "skyobjects/kssun.h"
29 #include "skyobjects/ksmoon.h"
30 #include "skyobjects/skyobject.h"
31 
32 
33 KSAlmanac::KSAlmanac() :
34  SunRise(0),
35  SunSet(0),
36  MoonRise(0),
37  MoonSet(0)
38 {
39  KStarsData* data = KStarsData::Instance();
40 
41  dt = KStarsDateTime::currentDateTime();
42  geo = data->geo();
43  dt.setTime(QTime());
44  dt = geo->LTtoUT(dt);
45  update();
46 }
47 
48 void KSAlmanac::update() {
49  RiseSetTime( &m_Sun, &SunRise, &SunSet, &SunRiseT, &SunSetT );
50  RiseSetTime( &m_Moon, &MoonRise, &MoonSet, &MoonRiseT, &MoonSetT );
51  findDawnDusk();
52 }
53 
54 void KSAlmanac::RiseSetTime( SkyObject *o, double *riseTime, double *setTime, QTime *RiseTime, QTime *SetTime ) {
55  // Compute object rise and set times
56  const KStarsDateTime today = dt;
57  const GeoLocation* _geo = geo;
58  *RiseTime = o->riseSetTime( today.addDays(1), _geo, true ); // The addDays(1) gives the future rise time rather than past
59  *SetTime = o->riseSetTime( today, _geo, false );
60  *riseTime = -1.0 * RiseTime->secsTo(QTime()) / 86400.0;
61  *setTime = -1.0 * SetTime->secsTo(QTime()) / 86400.0;
62 
63  // Check to see if the object is circumpolar
64  // NOTE: Since we are working on a local copy of the Sun / Moon,
65  // we freely change the geolocation / time without setting
66  // them back.
67 
68  KSNumbers num( dt.djd() );
69  dms LST = geo->GSTtoLST( dt.gst() );
70  o->updateCoords( &num, true, geo->lat(), &LST );
71  if ( o->checkCircumpolar( geo->lat() ) ) {
72  if ( o->alt().Degrees() > 0.0 ) {
73  //Circumpolar, signal it this way:
74  *riseTime = 0.0;
75  *setTime = 1.0;
76  } else {
77  //never rises, signal it this way:
78  *riseTime = 0.0;
79  *setTime = -1.0;
80  }
81  }
82 }
83 
84 // FIXME: This is utter code duplication. All this should be handled
85 // in the KStars engine. Forgive me for adding to the nonsense, but I
86 // want to get the Observation Planner functional first. -- asimha
87 
88 void KSAlmanac::findDawnDusk() {
89 
90  KStarsDateTime today = dt;
91  KSNumbers num( today.djd() );
92  dms LST = geo->GSTtoLST( today.gst() );
93 
94  m_Sun.updateCoords( &num, true, geo->lat(), &LST ); // We can abuse our own copy of the sun
95  double dawn, da, dusk, du, max_alt, min_alt;
96  double last_h = -12.0;
97  double last_alt = findAltitude( &m_Sun, last_h );
98  dawn = dusk = -13.0;
99  max_alt = -100.0;
100  min_alt = 100.0;
101  for ( double h=-11.95; h<=12.0; h+=0.05 ) {
102  double alt = findAltitude( &m_Sun, h );
103  bool asc = alt - last_alt > 0;
104  if ( alt > max_alt )
105  max_alt = alt;
106  if ( alt < min_alt )
107  min_alt = alt;
108 
109  if ( asc && last_alt <= -18.0 && alt >= -18.0 )
110  dawn = h;
111  if ( !asc && last_alt >= -18.0 && alt <= -18.0 )
112  dusk = h;
113 
114  last_h = h;
115  last_alt = alt;
116  }
117 
118  if ( dawn < -12.0 || dusk < -12.0 ) {
119  da = -1.0;
120  du = -1.0;
121  } else {
122  da = dawn / 24.0;
123  du = ( dusk + 24.0 ) / 24.0;
124  }
125 
126  DawnAstronomicalTwilight = da;
127  DuskAstronomicalTwilight = du;
128 }
129 
130 void KSAlmanac::setDate( KStarsDateTime *newdt ) {
131  dt = *newdt;
132  update();
133 }
134 
135 void KSAlmanac::setLocation( GeoLocation *m_geo ) {
136  geo = m_geo;
137  update();
138 }
139 
140 
141 double KSAlmanac::sunZenithAngleToTime( double z ) {
142  // TODO: Correct for movement of the sun
143  double HA = acos( ( cos( z * dms::DegToRad ) - m_Sun.dec().sin() * geo->lat()->sin() ) / (m_Sun.dec().cos() * geo->lat()->cos()) );
144  double HASunset = acos( ( -m_Sun.dec().sin() * geo->lat()->sin() ) / (m_Sun.dec().cos() * geo->lat()->cos()) );
145  return SunSet + ( HA - HASunset ) / 24.0;
146 }
147 
148 
149 double KSAlmanac::findAltitude( SkyPoint *p, double hour ) {
150  KStarsDateTime ut = dt;
151  ut.setTime( QTime() );
152  ut = geo->LTtoUT( ut );
153  ut= ut.addSecs( hour*3600.0 );
154  dms LST = geo->GSTtoLST( ut.gst() );
155  p->EquatorialToHorizontal( &LST, geo->lat() );
156  return p->alt().Degrees();
157 }
158 
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
KSAlmanac::setDate
void setDate(KStarsDateTime *newdt)
Set the date for computations to the given date.
Definition: ksalmanac.cpp:130
skyobject.h
KStarsDateTime::addDays
KStarsDateTime addDays(int nd) const
Modify the Date/Time by adding a number of days.
Definition: kstarsdatetime.h:117
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyObject::riseSetTime
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true)
Determine the time at which the point will rise or set.
Definition: skyobject.cpp:105
GeoLocation::LTtoUT
KStarsDateTime LTtoUT(const KStarsDateTime &lt) const
Definition: geolocation.h:234
SkyPoint::updateCoords
virtual void updateCoords(KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0), accounting for both precession and nutation.
Definition: skypoint.cpp:317
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
KSAlmanac::KSAlmanac
KSAlmanac()
Definition: ksalmanac.cpp:33
KStarsDateTime::setTime
void setTime(const QTime &t)
Assign the Time according to a QTime object.
Definition: kstarsdatetime.cpp:133
geolocation.h
dms.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SkyPoint::checkCircumpolar
bool checkCircumpolar(const dms *gLat)
Check if this point is circumpolar at the given geographic latitude.
Definition: skypoint.cpp:750
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
GeoLocation::GSTtoLST
dms GSTtoLST(const dms &gst) const
Definition: geolocation.h:230
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
KStarsDateTime::addSecs
KStarsDateTime addSecs(double s) const
Definition: kstarsdatetime.cpp:127
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
ksnumbers.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
KSPlanetBase::updateCoords
virtual void updateCoords(KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute=false)
Update position of the planet (reimplemented from SkyPoint)
Definition: ksplanetbase.cpp:105
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
KSAlmanac::sunZenithAngleToTime
double sunZenithAngleToTime(double z)
Convert the zenithal distance of the sun to fraction of the day.
Definition: ksalmanac.cpp:141
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
ksalmanac.h
kssun.h
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
ksmoon.h
kstarsdatetime.h
kstarsdata.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:138
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:46
KSAlmanac::setLocation
void setLocation(GeoLocation *m_geo)
Set the location for computations to the given location.
Definition: ksalmanac.cpp:135
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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