• 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
  • skyobjects
ksplanet.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksplanet.cpp - K Desktop Planetarium
3  -------------------
4  begin : Sun Jul 22 2001
5  copyright : (C) 2001 by Jason Harris
6  email : jharris@30doradus.org
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 "ksplanet.h"
19 
20 #include <cmath>
21 
22 #include <QFile>
23 #include <QTextStream>
24 
25 #include <kdebug.h>
26 #include <kglobal.h>
27 
28 #include "ksnumbers.h"
29 #include "ksutils.h"
30 #include "ksfilereader.h"
31 
32 KSPlanet::OrbitDataManager KSPlanet::odm;
33 
34 KSPlanet::OrbitDataColl::OrbitDataColl() {
35 }
36 
37 KSPlanet::OrbitDataManager::OrbitDataManager() {
38  //EMPTY
39 }
40 
41 bool KSPlanet::OrbitDataManager::readOrbitData(const QString &fname,
42  QVector<OrbitData> *vector)
43 {
44  QFile f;
45 
46  if ( KSUtils::openDataFile( f, fname ) ) {
47  KSFileReader fileReader( f ); // close file is included
48  QStringList fields;
49  while ( fileReader.hasMoreLines() ) {
50  fields = fileReader.readLine().split( ' ', QString::SkipEmptyParts );
51 
52  if ( fields.size() == 3 ) {
53  double A = fields[0].toDouble();
54  double B = fields[1].toDouble();
55  double C = fields[2].toDouble();
56  vector->append( OrbitData(A, B, C) );
57  }
58  }
59  } else {
60  return false;
61  }
62  return true;
63 }
64 
65 bool KSPlanet::OrbitDataManager::loadData( KSPlanet::OrbitDataColl &odc, const QString &n ) {
66  QString fname, snum, line;
67  QFile f;
68  int nCount = 0;
69  QString nl = n.toLower();
70 
71  if ( hash.contains( nl ) ) {
72  odc = hash[nl];
73  return true; //orbit data already loaded
74  }
75 
76  //Create a new OrbitDataColl
77  OrbitDataColl ret;
78 
79  //Ecliptic Longitude
80  for (int i=0; i<6; ++i) {
81  snum.setNum( i );
82  fname = nl + ".L" + snum + ".vsop";
83  if ( readOrbitData( fname, &ret.Lon[i] ) )
84  nCount++;
85  }
86 
87  if ( nCount==0 ) return false;
88 
89  //Ecliptic Latitude
90  for (int i=0; i<6; ++i) {
91  snum.setNum( i );
92  fname = nl + ".B" + snum + ".vsop";
93  if ( readOrbitData( fname, &ret.Lat[i] ) )
94  nCount++;
95  }
96 
97  if ( nCount==0 ) return false;
98 
99  //Heliocentric Distance
100  for (int i=0; i<6; ++i) {
101  snum.setNum( i );
102  fname = nl + ".R" + snum + ".vsop";
103  if ( readOrbitData( fname, &ret.Dst[i] ) )
104  nCount++;
105  }
106 
107  if ( nCount==0 ) return false;
108 
109  hash[nl] = ret;
110  odc = hash[nl];
111 
112  return true;
113 }
114 
115 KSPlanet::KSPlanet( const QString &s, const QString &imfile, const QColor & c, double pSize ) :
116  KSPlanetBase(s, imfile, c, pSize ),
117  data_loaded(false)
118 { }
119 
120 KSPlanet::KSPlanet( int n )
121  : KSPlanetBase()
122 {
123  switch ( n ) {
124  case MERCURY:
125  KSPlanetBase::init( i18n("Mercury"), "mercury", KSPlanetBase::planetColor[KSPlanetBase::MERCURY], 4879.4 );
126  break;
127  case VENUS:
128  KSPlanetBase::init( i18n("Venus"), "venus", KSPlanetBase::planetColor[KSPlanetBase::VENUS], 12103.6 );
129  break;
130  case MARS:
131  KSPlanetBase::init( i18n("Mars"), "mars", KSPlanetBase::planetColor[KSPlanetBase::MARS], 6792.4 );
132  break;
133  case JUPITER:
134  KSPlanetBase::init( i18n("Jupiter"), "jupiter", KSPlanetBase::planetColor[KSPlanetBase::JUPITER], 142984. );
135  break;
136  case SATURN:
137  KSPlanetBase::init( i18n("Saturn"), "saturn", KSPlanetBase::planetColor[KSPlanetBase::SATURN], 120536. );
138  break;
139  case URANUS:
140  KSPlanetBase::init( i18n("Uranus"), "uranus", KSPlanetBase::planetColor[KSPlanetBase::URANUS], 51118. );
141  break;
142  case NEPTUNE:
143  KSPlanetBase::init( i18n("Neptune"), "neptune", KSPlanetBase::planetColor[KSPlanetBase::NEPTUNE], 49572. );
144  break;
145  default:
146  kDebug() << i18n("Error: Illegal identifier in KSPlanet constructor: %1", n) << endl;
147  break;
148  }
149 }
150 
151 KSPlanet* KSPlanet::clone() const
152 {
153  return new KSPlanet(*this);
154 }
155 
156 // TODO: Get rid of this dirty hack post KDE 4.2 release
157 QString KSPlanet::untranslatedName() const {
158  if( name() == i18n( "Mercury" ) )
159  return "Mercury";
160  else if( name() == i18n( "Venus" ) )
161  return "Venus";
162  else if( name() == i18n( "Mars" ) )
163  return "Mars";
164  else if( name() == i18n( "Jupiter" ) )
165  return "Jupiter";
166  else if( name() == i18n( "Saturn" ) )
167  return "Saturn";
168  else if( name() == i18n( "Uranus" ) )
169  return "Uranus";
170  else if( name() == i18n( "Neptune" ) )
171  return "Neptune";
172  else
173  return name();
174 }
175 
176 //we don't need the reference to the ODC, so just give it a junk variable
177 bool KSPlanet::loadData() {
178  OrbitDataColl odc;
179  return odm.loadData( odc, untranslatedName() );
180 }
181 
182 void KSPlanet::calcEcliptic(double Tau, EclipticPosition &epret) const {
183  double sum[6];
184  OrbitDataColl odc;
185  double Tpow[6];
186 
187  Tpow[0] = 1.0;
188  for (int i=1; i<6; ++i) {
189  Tpow[i] = Tpow[i-1] * Tau;
190  }
191 
192  if ( ! odm.loadData( odc, untranslatedName() ) ) {
193  epret.longitude = dms(0.0);
194  epret.latitude = dms(0.0);
195  epret.radius = 0.0;
196  kError() << "Could not get data for '" << name() << "'" << endl;
197  return;
198  }
199 
200  //Ecliptic Longitude
201  for (int i=0; i<6; ++i) {
202  sum[i] = 0.0;
203  for (int j = 0; j < odc.Lon[i].size(); ++j) {
204  sum[i] += odc.Lon[i][j].A * cos( odc.Lon[i][j].B + odc.Lon[i][j].C*Tau );
205  /*
206  kDebug() << "sum[" << i <<"] =" << sum[i] <<
207  " A = " << odc.Lon[i][j].A << " B = " << odc.Lon[i][j].B <<
208  " C = " << odc.Lon[i][j].C << endl;
209  */
210  }
211  sum[i] *= Tpow[i];
212  //kDebug() << name() << " : sum[" << i << "] = " << sum[i];
213  }
214 
215  epret.longitude.setRadians( sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5] );
216  epret.longitude.setD( epret.longitude.reduce().Degrees() );
217 
218  //Compute Ecliptic Latitude
219  for (uint i=0; i<6; ++i) {
220  sum[i] = 0.0;
221  for (int j = 0; j < odc.Lat[i].size(); ++j) {
222  sum[i] += odc.Lat[i][j].A * cos( odc.Lat[i][j].B + odc.Lat[i][j].C*Tau );
223  }
224  sum[i] *= Tpow[i];
225  }
226 
227 
228  epret.latitude.setRadians( sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5] );
229 
230  //Compute Heliocentric Distance
231  for (uint i=0; i<6; ++i) {
232  sum[i] = 0.0;
233  for (int j = 0; j < odc.Dst[i].size(); ++j) {
234  sum[i] += odc.Dst[i][j].A * cos( odc.Dst[i][j].B + odc.Dst[i][j].C*Tau );
235  }
236  sum[i] *= Tpow[i];
237  }
238 
239  epret.radius = sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5];
240 
241  /*
242  kDebug() << name() << " pre: Lat = " << epret.latitude.toDMSString() << " Long = " <<
243  epret.longitude.toDMSString() << " Dist = " << epret.radius << endl;
244  */
245 
246 }
247 
248 bool KSPlanet::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
249 
250  if ( Earth != NULL ) {
251  double sinL, sinL0, sinB, sinB0;
252  double cosL, cosL0, cosB, cosB0;
253  double x = 0.0, y = 0.0, z = 0.0;
254 
255  double olddst = -1000;
256  double dst = 0;
257 
258  EclipticPosition trialpos;
259 
260  double jm = num->julianMillenia();
261 
262  Earth->ecLong().SinCos( sinL0, cosL0 );
263  Earth->ecLat().SinCos( sinB0, cosB0 );
264 
265  double eX = Earth->rsun()*cosB0*cosL0;
266  double eY = Earth->rsun()*cosB0*sinL0;
267  double eZ = Earth->rsun()*sinB0;
268 
269  bool once=true;
270  while (fabs(dst - olddst) > .001) {
271  calcEcliptic(jm, trialpos);
272 
273  // We store the heliocentric ecliptic coordinates the first time they are computed.
274  if(once){
275  helEcPos = trialpos;
276  once=false;
277  }
278 
279  olddst = dst;
280 
281  trialpos.longitude.SinCos( sinL, cosL );
282  trialpos.latitude.SinCos( sinB, cosB );
283 
284  x = trialpos.radius*cosB*cosL - eX;
285  y = trialpos.radius*cosB*sinL - eY;
286  z = trialpos.radius*sinB - eZ;
287 
288  //distance from Earth
289  dst = sqrt(x*x + y*y + z*z);
290 
291  //The light-travel time delay, in millenia
292  //0.0057755183 is the inverse speed of light,
293  //in days/AU
294  double delay = (.0057755183 * dst) / 365250.0;
295 
296  jm = num->julianMillenia() - delay;
297 
298  }
299 
300  ep.longitude.setRadians( atan2( y, x ) );
301  ep.longitude.reduce();
302  ep.latitude.setRadians( atan2( z, sqrt( x*x + y*y ) ) );
303  setRsun( trialpos.radius );
304  setRearth( dst );
305 
306  EclipticToEquatorial( num->obliquity() );
307 
308  nutate(num);
309  aberrate(num);
310 
311  } else {
312 
313  calcEcliptic(num->julianMillenia(), ep);
314  helEcPos = ep;
315  }
316 
317  //determine the position angle
318  findPA( num );
319 
320  return true;
321 }
322 
323 void KSPlanet::findMagnitude(const KSNumbers* num)
324 {
325  double cosDec, sinDec;
326  dec().SinCos(cosDec, sinDec);
327 
328  /* Computation of the visual magnitude (V band) of the planet.
329  * Algorithm provided by Pere Planesas (Observatorio Astronomico Nacional)
330  * It has some simmilarity to J. Meeus algorithm in Astronomical Algorithms, Chapter 40.
331  * */
332 
333  // Initialized to the faintest magnitude observable with the HST
334  float magnitude = 30;
335 
336  double param = 5 * log10(rsun() * rearth() );
337  double phase = this->phase().Degrees();
338  double f1 = phase/100.;
339 
340  if( name() == i18n( "Mercury" ) ) {
341  if ( phase > 150. ) f1 = 1.5;
342  magnitude = -0.36 + param + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1;
343  } else if( name() == i18n( "Venus" ) ) {
344  magnitude = -4.29 + param + 0.09*f1 + 2.39*f1*f1 - 0.65*f1*f1*f1;
345  } else if( name() == i18n( "Mars" ) ) {
346  magnitude = -1.52 + param + 0.016*phase;
347  } else if( name() == i18n( "Jupiter" ) ) {
348  magnitude = -9.25 + param + 0.005*phase;
349  } else if( name() == i18n( "Saturn" ) ) {
350  double T = num->julianCenturies();
351  double a0 = (40.66-4.695*T)* dms::PI / 180.;
352  double d0 = (83.52+0.403*T)* dms::PI / 180.;
353  double sinx = -cos(d0)*cosDec*cos(a0 - ra().radians());
354  sinx = fabs(sinx-sin(d0)*sinDec);
355  double rings = -2.6*sinx + 1.25*sinx*sinx;
356  magnitude = -8.88 + param + 0.044*phase + rings;
357  } else if( name() == i18n( "Uranus" ) ) {
358  magnitude = -7.19 + param + 0.0028*phase;
359  } else if( name() == i18n( "Neptune" ) ) {
360  magnitude = -6.87 + param;
361  }
362  setMag(magnitude);
363 }
364 
365 SkyObject::UID KSPlanet::getUID() const
366 {
367  SkyObject::UID n;
368  if( name() == i18n( "Mercury" ) ) {
369  n = 1;
370  } else if( name() == i18n( "Venus" ) ) {
371  n = 2;
372  } else if( name() == i18n( "Earth" ) ) {
373  n = 3;
374  } else if( name() == i18n( "Mars" ) ) {
375  n = 4;
376  } else if( name() == i18n( "Jupiter" ) ) {
377  n = 5;
378  } else if( name() == i18n( "Saturn" ) ) {
379  n = 6;
380  } else if( name() == i18n( "Uranus" ) ) {
381  n = 7;
382  } else if( name() == i18n( "Neptune" ) ) {
383  n = 8;
384  } else {
385  return SkyObject::invalidUID;
386  }
387  return solarsysUID(UID_SOL_BIGOBJ) | n;
388 }
KSPlanetBase::setRearth
void setRearth(double r)
Set the distance from Earth, in AU.
Definition: ksplanetbase.h:139
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
KSPlanet::OrbitDataManager::loadData
bool loadData(OrbitDataColl &odc, const QString &n)
Load orbital data for a planet from disk.
Definition: ksplanet.cpp:65
KSPlanetBase::NEPTUNE
Definition: ksplanetbase.h:82
KSPlanet
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition: ksplanet.h:40
KSPlanet::clone
virtual KSPlanet * clone() const
Create copy of object.
Definition: ksplanet.cpp:151
SkyPoint::aberrate
void aberrate(const KSNumbers *num)
Determine the effects of aberration for this SkyPoint.
Definition: skypoint.cpp:287
SkyPoint::nutate
void nutate(const KSNumbers *num)
Determine the effects of nutation for this SkyPoint.
Definition: skypoint.cpp:202
KSPlanetBase::JUPITER
Definition: ksplanetbase.h:82
SkyObject::invalidUID
static const UID invalidUID
Invalid UID.
Definition: skyobject.h:62
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
KSPlanetBase::setRsun
void setRsun(double r)
Set the solar distance in AU.
Definition: ksplanetbase.h:131
KSPlanet::odm
static OrbitDataManager odm
Definition: ksplanet.h:179
EclipticPosition::latitude
dms latitude
Definition: ksplanetbase.h:43
KSPlanet::OrbitDataColl::OrbitDataColl
OrbitDataColl()
Constructor.
Definition: ksplanet.cpp:34
KSPlanet::getUID
virtual SkyObject::UID getUID() const
Return UID for object.
Definition: ksplanet.cpp:365
KSPlanetBase::MERCURY
Definition: ksplanetbase.h:82
KSPlanet::findGeocentricPosition
virtual bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth=NULL)
Calculate the geocentric RA, Dec coordinates of the Planet.
Definition: ksplanet.cpp:248
KSPlanet::loadData
virtual bool loadData()
Preload the data used by findPosition.
Definition: ksplanet.cpp:177
KSPlanet::OrbitDataColl
OrbitDataColl contains three groups of six QVectors.
Definition: ksplanet.h:135
KSUtils::openDataFile
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
ksplanet.h
KSPlanetBase::UID_SOL_BIGOBJ
static const UID UID_SOL_BIGOBJ
Big object.
Definition: ksplanetbase.h:203
NaN::f
const float f
Definition: nan.h:36
KSPlanetBase::init
void init(const QString &s, const QString &image_file, const QColor &c, double pSize)
Definition: ksplanetbase.cpp:64
KSPlanetBase::ep
EclipticPosition ep
Definition: ksplanetbase.h:238
KSPlanetBase::findPA
void findPA(const KSNumbers *num)
Determine the position angle of the planet for a given date (used internally by findPosition() ) ...
Definition: ksplanetbase.cpp:240
KSPlanetBase::solarsysUID
UID solarsysUID(UID type) const
Compute high 32-bits of UID.
Definition: ksplanetbase.h:210
KSPlanetBase::helEcPos
EclipticPosition helEcPos
Definition: ksplanetbase.h:242
KSPlanetBase::MARS
Definition: ksplanetbase.h:82
KSPlanetBase::rsun
double rsun() const
Definition: ksplanetbase.h:126
KSPlanet::calcEcliptic
virtual void calcEcliptic(double jm, EclipticPosition &ret) const
Calculate the ecliptic longitude and latitude of the planet for the given date (expressed in Julian M...
Definition: ksplanet.cpp:182
KSPlanet::KSPlanet
KSPlanet(const QString &s="unnamed", const QString &image_file=QString(), const QColor &c=Qt::white, double pSize=0)
Constructor.
Definition: ksplanet.cpp:115
EclipticPosition
The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
Definition: ksplanetbase.h:40
SkyObject::UID
qint64 UID
Type for Unique object IDenticator.
Definition: skyobject.h:53
ksnumbers.h
KSPlanet::untranslatedName
QString untranslatedName(void) const
return the untranslated name This is a dirty way to solve a lot of localization-related trouble for t...
Definition: ksplanet.cpp:157
KSNumbers::obliquity
const dms * obliquity() const
Definition: ksnumbers.h:58
KSPlanetBase::EclipticToEquatorial
void EclipticToEquatorial(const dms *Obliquity)
Convert Ecliptic logitude/latitude to Right Ascension/Declination.
Definition: ksplanetbase.cpp:101
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
KSPlanet::OrbitDataManager
OrbitDataManager places the OrbitDataColl objects for all planets in a QDict indexed by the planets' ...
Definition: ksplanet.h:152
EclipticPosition::longitude
dms longitude
Definition: ksplanetbase.h:42
KSPlanetBase::SATURN
Definition: ksplanetbase.h:82
KSPlanet::data_loaded
bool data_loaded
Definition: ksplanet.h:88
KSPlanetBase::ecLat
const dms & ecLat() const
Definition: ksplanetbase.h:94
SkyObject::setMag
void setMag(float m)
Set the object's sorting magnitude.
Definition: skyobject.h:409
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
KSPlanetBase::ecLong
const dms & ecLong() const
Definition: ksplanetbase.h:91
ksfilereader.h
KSFileReader
Definition: ksfilereader.h:65
KSPlanetBase::rearth
double rearth() const
Definition: ksplanetbase.h:134
PI
#define PI
Definition: satellite.cpp:43
EclipticPosition::radius
double radius
Definition: ksplanetbase.h:44
KSPlanet::OrbitDataColl::Dst
OBArray Dst
Definition: ksplanet.h:142
KSPlanet::OrbitDataManager::OrbitDataManager
OrbitDataManager()
Constructor.
Definition: ksplanet.cpp:37
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
KSPlanet::OrbitDataColl::Lat
OBArray Lat
Definition: ksplanet.h:141
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
KSPlanetBase::VENUS
Definition: ksplanetbase.h:82
KSNumbers::julianCenturies
double julianCenturies() const
Definition: ksnumbers.h:90
KSPlanetBase::planetColor
static QVector< QColor > planetColor
Definition: ksplanetbase.h:86
KSPlanet::OrbitData
This class contains doubles A,B,C which represent a single term in a planet's positional expansion su...
Definition: ksplanet.h:104
ksutils.h
KSPlanetBase::URANUS
Definition: ksplanetbase.h:82
KSNumbers::julianMillenia
double julianMillenia() const
Definition: ksnumbers.h:96
KSPlanetBase::phase
dms phase()
Definition: ksplanetbase.h:187
KSPlanet::OrbitDataColl::Lon
OBArray Lon
Definition: ksplanet.h:140
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