• 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
  • tools
ksconjunct.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksconjunct.cpp - K Desktop Planetarium
3  -------------------
4  begin : Sat Mar 22 2008
5  copyright : (C) 2008 by Akarsh Simha
6  email : kstar@bas.org.in
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "ksconjunct.h"
19 
20 #include <cmath>
21 
22 #include "ksnumbers.h"
23 #include "skyobjects/ksplanetbase.h"
24 #include "skyobjects/ksplanet.h"
25 #include "skyobjects/ksasteroid.h"
26 #include "skyobjects/kscomet.h"
27 #include "kstarsdata.h"
28 
29 KSConjunct::KSConjunct() {
30  geoPlace = KStarsData::Instance()->geo();
31 }
32 
33 void KSConjunct::setGeoLocation( GeoLocation *geo ) {
34  if( geo != NULL )
35  geoPlace = geo;
36  else
37  geoPlace = KStarsData::Instance()->geo();
38 }
39 
40 QMap<long double, dms> KSConjunct::findClosestApproach(SkyObject& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation,bool _opposition) {
41 
42  QMap<long double, dms> Separations;
43  QPair<long double, dms> extremum;
44  dms Dist;
45  dms prevDist;
46  double step, step0;
47  int Sign, prevSign;
48  opposition=_opposition;
49  // kDebug() << "Entered KSConjunct::findClosestApproach() with startJD = " << (double)startJD;
50  // kDebug() << "Initial Positional Information: \n";
51  // kDebug() << Object1.name() << ": RA = " << Object1.ra() -> toHMSString() << "; Dec = " << Object1.dec() -> toDMSString() << "\n";
52  // kDebug() << Object2.name() << ": RA = " << Object2.ra() -> toHMSString() << "; Dec = " << Object2.dec() -> toDMSString() << "\n";
53  prevSign = 0;
54 
55  step0 = (stopJD - startJD) / 4.0; // I'm an idiot for having done this without having the lines that follow -- asimha
56 
57  // TODO: Work out a solid footing on which one can decide step0. -- asimha
58  if( step0 > 24.8 * 365.25 ) // Sample pluto's orbit (248.09 years) at least 10 times.
59  step0 = 24.8 * 365.25;
60 
61  // FIXME: This can be done better, but for now, I'm doing it the dumb way -- asimha
62  if( Object1.name() == i18n( "Neptune" ) || Object2.name() == i18n( "Neptune" ) || Object1.name() == i18n( "Uranus" ) || Object2.name() == i18n( "Uranus" ) )
63  if( step0 > 3652.5 )
64  step0 = 3652.5;
65  if( Object1.name() == i18n( "Jupiter" ) || Object2.name() == i18n( "Jupiter" ) || Object1.name() == i18n( "Saturn" ) || Object2.name() == i18n( "Saturn" ) )
66  if( step0 > 365.25 )
67  step0 = 365;
68  if(Object1.name() == i18n( "Mars" ) || Object2.name() == i18n( "Mars" ))
69  if (step0 > 10.0)
70  step0 = 10.0;
71  if(Object1.name() == i18n( "Venus" ) || Object1.name() == i18n( "Mercury" ) || Object2.name() == i18n( "Mercury" ) || Object2.name() == i18n( "Venus" ))
72  if (step0 > 5.0)
73  step0 = 5.0;
74  if(Object1.name() == "Moon" || Object2.name() == "Moon")
75  if (step0 > 0.25)
76  step0 = 0.25;
77 
78  step = step0;
79 
80  // kDebug() << "Initial Separation between " << Object1.name() << " and " << Object2.name() << " = " << (prevDist.toDMSString());
81 
82  long double jd = startJD;
83  prevDist = findDistance(jd, &Object1, &Object2);
84  jd += step;
85  while ( jd <= stopJD ) {
86  int progress = int( 100.0*(jd - startJD)/(stopJD - startJD) );
87  emit madeProgress( progress );
88 
89  Dist = findDistance(jd, &Object1, &Object2);
90  Sign = sgn(Dist - prevDist);
91  // kDebug() << "Dist = " << Dist.toDMSString() << "; prevDist = " << prevDist.toDMSString() << "; Difference = " << (Dist.Degrees() - prevDist.Degrees()) << "; Step = " << step;
92 
93  //How close are we to a conjunction, and how fast are we approaching one?
94  double factor = fabs( (Dist.Degrees() - prevDist.Degrees()) / Dist.Degrees());
95  if ( factor > 10.0 ) { //let's go faster!
96  step = step0 * factor/10.0;
97  } else { //slow down, we're getting close!
98  step = step0;
99  }
100 
101  if( Sign != prevSign && prevSign == -1) { //all right, we may have just passed a conjunction
102  if ( step > step0 ) { //mini-loop to back up and make sure we're close enough
103  // kDebug() << "Entering slow loop: " << endl;
104  jd -= step;
105  step = step0;
106  Sign = prevSign;
107  while ( jd <= stopJD ) {
108  Dist = findDistance(jd, &Object1, &Object2);
109  Sign = sgn(Dist - prevDist);
110  // kDebug() << "Dist=" << Dist.toDMSString() << "; prevDist=" << prevDist.toDMSString() << "; Diff=" << (Dist.Degrees() - prevDist.Degrees()) << "djd=" << (int)(jd - startJD);
111  if ( Sign != prevSign ) break;
112 
113  prevDist = Dist;
114  prevSign = Sign;
115  jd += step;
116  }
117  }
118 
119  // kDebug() << "Sign = " << Sign << " and " << "prevSign = " << prevSign << ": Entering findPrecise()\n";
120  if(findPrecise(&extremum, &Object1, &Object2, jd, step, Sign))
121  if(extremum.second.radians() < maxSeparation.radians())
122  Separations.insert(extremum.first, extremum.second);
123  }
124 
125  prevDist = Dist;
126  prevSign = Sign;
127  jd += step;
128  }
129 
130  return Separations;
131 }
132 
133 
134 dms KSConjunct::findDistance(long double jd, SkyObject *Object1, KSPlanetBase *Object2)
135 {
136  KStarsDateTime t(jd);
137  KSNumbers num(jd);
138  dms dist;
139 
140  KSPlanet *m_Earth = new KSPlanet( I18N_NOOP( "Earth" ), QString(), QColor( "white" ), 12756.28 /*diameter in km*/ );
141  m_Earth -> findPosition( &num );
142  dms LST(geoPlace->GSTtoLST(t.gst()));
143 
144  KSPlanetBase* p = dynamic_cast<KSPlanetBase*>(Object1);
145  if( p )
146  p->findPosition(&num, geoPlace->lat(), &LST, m_Earth);
147  else
148  Object1->updateCoords( &num );
149 
150  Object2->findPosition(&num, geoPlace->lat(), &LST, m_Earth);
151  dist.setRadians(Object1 -> angularDistanceTo(Object2).radians());
152  if( opposition ) {
153  dist.setD( 180 - dist.Degrees() );
154  }
155  return dist;
156 }
157 
158 bool KSConjunct::findPrecise(QPair<long double, dms> *out, SkyObject *Object1, KSPlanetBase *Object2, long double jd, double step, int prevSign) {
159  dms prevDist;
160  int Sign;
161  dms Dist;
162 
163  if( out == NULL ) {
164  kDebug() << "ERROR: Argument out to KSConjunct::findPrecise(...) was NULL!";
165  return false;
166  }
167 
168  prevDist = findDistance(jd, Object1, Object2);
169 
170  step = -step / 2.0;
171  prevSign = -prevSign;
172 
173  while(true) {
174  jd += step;
175  Dist = findDistance(jd, Object1, Object2);
176  // kDebug() << "Dist=" << Dist.toDMSString() << "; prevDist=" << prevDist.toDMSString() << "; Diff=" << (Dist.Degrees() - prevDist.Degrees()) << "step=" << step;
177 
178  if(fabs(step) < 1.0 / (24.0*60.0) ) {
179  out -> first = jd - step / 2.0;
180  out -> second = findDistance(jd - step/2.0, Object1, Object2);
181  if(out -> second.radians() < findDistance(jd - 5.0, Object1, Object2).radians())
182  return true;
183  else
184  return false;
185  }
186  Sign = sgn(Dist - prevDist);
187  if(Sign != prevSign) {
188  step = -step / 2.0;
189  Sign = -Sign;
190  }
191  prevSign = Sign;
192  prevDist = Dist;
193  }
194 }
195 
196 int KSConjunct::sgn(dms a) {
197 
198  // Auxiliary function used by the KSConjunct::findClosestApproach(...)
199  // method and the KSConjunct::findPrecise(...) method
200 
201  return ((a.radians() > 0)?1:((a.radians() < 0)?-1:0));
202 
203 }
204 #include "ksconjunct.moc"
KSConjunct::setGeoLocation
void setGeoLocation(GeoLocation *geo)
Sets the geographic location to compute conjunctions at.
Definition: ksconjunct.cpp:33
KSPlanetBase::findPosition
void findPosition(const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth=0)
Find position, including correction for Figure-of-the-Earth.
Definition: ksplanetbase.cpp:122
ksplanetbase.h
ksconjunct.h
KSPlanet
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition: ksplanet.h:40
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
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
ksplanet.h
KSConjunct::findClosestApproach
QMap< long double, dms > findClosestApproach(SkyObject &Object1, KSPlanetBase &Object2, long double startJD, long double stopJD, dms maxSeparation, bool _opposition=false)
Compute the closest approach of two planets in the given range.
Definition: ksconjunct.cpp:40
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
Sign
Sign
Definition: SpatialSign.h:8
KSConjunct::madeProgress
void madeProgress(int progress)
GeoLocation::GSTtoLST
dms GSTtoLST(const dms &gst) const
Definition: geolocation.h:230
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
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
kscomet.h
KSConjunct::KSConjunct
KSConjunct()
Constructor.
Definition: ksconjunct.cpp:29
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
ksasteroid.h
kstarsdata.h
dms::setD
void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition: dms.h:130
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
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
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