• 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
ksplanetbase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksplanetbase.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 "ksplanetbase.h"
19 
20 #include <cmath>
21 
22 #include <QFile>
23 #include <QPoint>
24 #include <QMatrix>
25 
26 #include "kstarsdata.h"
27 #include "ksutils.h"
28 #include "ksnumbers.h"
29 #include "Options.h"
30 #include "skymap.h"
31 #include "ksasteroid.h"
32 #include "kscomet.h"
33 #include "kspluto.h"
34 #include "ksplanet.h"
35 #include "kssun.h"
36 #include "ksmoon.h"
37 #include "skycomponents/skymapcomposite.h"
38 #include "texturemanager.h"
39 
40 QVector<QColor> KSPlanetBase::planetColor = QVector<QColor>() <<
41  QColor("slateblue") << //Mercury
42  QColor("lightgreen") << //Venus
43  QColor("red") << //Mars
44  QColor("goldenrod") << //Jupiter
45  QColor("khaki") << //Saturn
46  QColor("lightseagreen") << //Uranus
47  QColor("skyblue") << //Neptune
48  QColor("grey") << //Pluto
49  QColor("yellow") << //Sun
50  QColor("white"); //Moon
51 
52 
53 const SkyObject::UID KSPlanetBase::UID_SOL_BIGOBJ = 0;
54 const SkyObject::UID KSPlanetBase::UID_SOL_ASTEROID = 1;
55 const SkyObject::UID KSPlanetBase::UID_SOL_COMET = 2;
56 
57 KSPlanetBase::KSPlanetBase( const QString &s, const QString &image_file, const QColor &c, double pSize ) :
58  TrailObject( 2, 0.0, 0.0, 0.0, s ),
59  Rearth(0.0)
60 {
61  init( s, image_file, c, pSize );
62 }
63 
64 void KSPlanetBase::init( const QString &s, const QString &image_file, const QColor &c, double pSize ) {
65  m_image = TextureManager::getImage( image_file );
66  PositionAngle = 0.0;
67  PhysicalSize = pSize;
68  m_Color = c;
69  setName( s );
70  setLongName( s );
71 }
72 
73 KSPlanetBase* KSPlanetBase::createPlanet( int n ) {
74  switch ( n ) {
75  case KSPlanetBase::MERCURY:
76  case KSPlanetBase::VENUS:
77  case KSPlanetBase::MARS:
78  case KSPlanetBase::JUPITER:
79  case KSPlanetBase::SATURN:
80  case KSPlanetBase::URANUS:
81  case KSPlanetBase::NEPTUNE:
82  return new KSPlanet( n );
83  break;
84  case KSPlanetBase::PLUTO:
85  return new KSPluto();
86  break;
87  case KSPlanetBase::SUN:
88  return new KSSun();
89  break;
90  case KSPlanetBase::MOON:
91  return new KSMoon();
92  break;
93  }
94  return 0;
95 }
96 
97 void KSPlanetBase::EquatorialToEcliptic( const dms *Obliquity ) {
98  findEcliptic( Obliquity, ep.longitude, ep.latitude );
99 }
100 
101 void KSPlanetBase::EclipticToEquatorial( const dms *Obliquity ) {
102  setFromEcliptic( Obliquity, ep.longitude, ep.latitude );
103 }
104 
105 void KSPlanetBase::updateCoords( KSNumbers *num, bool includePlanets, const dms *lat, const dms *LST, bool )
106 {
107  KStarsData *kd = KStarsData::Instance();
108  if ( includePlanets ) {
109  kd->skyComposite()->earth()->findPosition( num ); //since we don't pass lat & LST, localizeCoords will be skipped
110 
111  if ( lat && LST ) {
112  findPosition( num, lat, LST, kd->skyComposite()->earth() );
113  //Don't add to the trail this time
114  if( hasTrail() )
115  Trail.takeLast();
116  } else {
117  findGeocentricPosition( num, kd->skyComposite()->earth() );
118  }
119  }
120 }
121 
122 void KSPlanetBase::findPosition( const KSNumbers *num, const dms *lat, const dms *LST, const KSPlanetBase *Earth ) {
123  // DEBUG edit
124  findGeocentricPosition( num, Earth ); //private function, reimplemented in each subclass
125  findPhase();
126  setAngularSize( asin(physicalSize()/Rearth/AU_KM)*60.*180./dms::PI ); //angular size in arcmin
127 
128  if ( lat && LST )
129  localizeCoords( num, lat, LST ); //correct for figure-of-the-Earth
130 
131  if ( hasTrail() ) {
132  addToTrail();
133  if ( Trail.size() > TrailObject::MaxTrail )
134  clipTrail();
135  }
136 
137  findMagnitude(num);
138 
139  if ( type() == SkyObject::COMET ) {
140  // Compute tail size
141  KSComet *me = (KSComet *)this;
142  double TailAngSize;
143  // Convert the tail size in km to angular tail size (degrees)
144  TailAngSize = asin(physicalSize()/Rearth/AU_KM)*60.0*180.0/dms::PI;
145  // Find the apparent length as projected on the celestial sphere (the comet's tail points away from the sun)
146  me->setTailAngSize( TailAngSize * fabs(sin( phase().radians() )));
147  }
148 
149 }
150 
151 bool KSPlanetBase::isMajorPlanet() const {
152  if ( name() == i18n( "Mercury" ) || name() == i18n( "Venus" ) || name() == i18n( "Mars" ) ||
153  name() == i18n( "Jupiter" ) || name() == i18n( "Saturn" ) || name() == i18n( "Uranus" ) ||
154  name() == i18n( "Neptune" ) )
155  return true;
156  return false;
157 }
158 
159 void KSPlanetBase::localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST ) {
160  //convert geocentric coordinates to local apparent coordinates (topocentric coordinates)
161  dms HA, HA2; //Hour Angle, before and after correction
162  double rsinp, rcosp, u, sinHA, cosHA, sinDec, cosDec, D;
163  double cosHA2;
164  double r = Rearth * AU_KM; //distance from Earth, in km
165  u = atan( 0.996647*tan( lat->radians() ) );
166  rsinp = 0.996647*sin( u );
167  rcosp = cos( u );
168  HA.setD( LST->Degrees() - ra().Degrees() );
169  HA.SinCos( sinHA, cosHA );
170  dec().SinCos( sinDec, cosDec );
171 
172  D = atan2( rcosp*sinHA, r*cosDec/6378.14 - rcosp*cosHA );
173  dms temp;
174  temp.setRadians( ra().radians() - D );
175  setRA( temp );
176 
177  HA2.setD( LST->Degrees() - ra().Degrees() );
178  cosHA2 = cos( HA2.radians() );
179 
180  //temp.setRadians( atan2( cosHA2*( r*sinDec/6378.14 - rsinp ), r*cosDec*cosHA/6378.14 - rcosp ) );
181  // The atan2() version above makes the planets move crazy in the htm branch -jbb
182  temp.setRadians( atan( cosHA2*( r*sinDec/6378.14 - rsinp )/( r*cosDec*cosHA/6378.14 - rcosp ) ) );
183 
184  setDec( temp );
185 
186  //Make sure Dec is between -90 and +90
187  if ( dec().Degrees() > 90.0 ) {
188  setDec( 180.0 - dec().Degrees() );
189  setRA( ra().Hours() + 12.0 );
190  ra().reduce();
191  }
192  if ( dec().Degrees() < -90.0 ) {
193  setDec( 180.0 + dec().Degrees() );
194  setRA( ra().Hours() + 12.0 );
195  ra().reduce();
196  }
197 
198  EquatorialToEcliptic( num->obliquity() );
199 }
200 
201 void KSPlanetBase::setRearth( const KSPlanetBase *Earth ) {
202  double sinL, sinB, sinL0, sinB0;
203  double cosL, cosB, cosL0, cosB0;
204  double x,y,z;
205 
206  //The Moon's Rearth is set in its findGeocentricPosition()...
207  if ( name() == "Moon" ) {
208  return;
209  }
210 
211  if ( name() == "Earth" ) {
212  Rearth = 0.0;
213  return;
214  }
215 
216  if ( ! Earth ) {
217  kDebug() << i18n( "KSPlanetBase::setRearth(): Error: Need an Earth pointer. (" ) << name() << ")";
218  Rearth = 1.0;
219  return;
220  }
221 
222  Earth->ecLong().SinCos( sinL0, cosL0 );
223  Earth->ecLat().SinCos( sinB0, cosB0 );
224  double eX = Earth->rsun()*cosB0*cosL0;
225  double eY = Earth->rsun()*cosB0*sinL0;
226  double eZ = Earth->rsun()*sinB0;
227 
228  helEcLong().SinCos( sinL, cosL );
229  helEcLat().SinCos( sinB, cosB );
230  x = rsun()*cosB*cosL - eX;
231  y = rsun()*cosB*sinL - eY;
232  z = rsun()*sinB - eZ;
233 
234  Rearth = sqrt(x*x + y*y + z*z);
235 
236  //Set angular size, in arcmin
237  AngularSize = asin(PhysicalSize/Rearth/AU_KM)*60.*180./dms::PI;
238 }
239 
240 void KSPlanetBase::findPA( const KSNumbers *num ) {
241  //Determine position angle of planet (assuming that it is aligned with
242  //the Ecliptic, which is only roughly correct).
243  //Displace a point along +Ecliptic Latitude by 1 degree
244  SkyPoint test;
245  dms newELat( ecLat().Degrees() + 1.0 );
246  test.setFromEcliptic( num->obliquity(), ecLong(), newELat );
247  double dx = ra().Degrees() - test.ra().Degrees();
248  double dy = test.dec().Degrees() - dec().Degrees();
249  double pa;
250  if ( dy ) {
251  pa = atan2( dx, dy )*180.0/dms::PI;
252  } else {
253  pa = dx < 0 ? 90.0 : -90.0;
254  }
255  setPA( pa );
256 }
257 
258 double KSPlanetBase::labelOffset() const {
259  double size = angSize() * dms::PI * Options::zoomFactor()/10800.0;
260 
261  //Determine minimum size for offset
262  double minsize = 4.;
263  if ( type() == SkyObject::ASTEROID || type() == SkyObject::COMET )
264  minsize = 2.;
265  if ( name() == "Sun" || name() == "Moon" )
266  minsize = 8.;
267  if ( size < minsize )
268  size = minsize;
269 
270  //Inflate offset for Saturn
271  if ( name() == i18n( "Saturn" ) )
272  size = int(2.5*size);
273 
274  return 0.5*size + 4.;
275 }
276 
277 void KSPlanetBase::findPhase() {
278  /* Compute the phase of the planet in degrees */
279  double earthSun = KStarsData::Instance()->skyComposite()->earth()->rsun();
280  double cosPhase = (rsun()*rsun() + rearth()*rearth() - earthSun*earthSun)
281  / (2 * rsun() * rearth() );
282  Phase = acos ( cosPhase ) * 180.0 / dms::PI;
283  /* More elegant way of doing it, but requires the Sun.
284  TODO: Switch to this if and when we make KSSun a singleton */
285  // Phase = ecLong()->Degrees() - Sun->ecLong()->Degrees();
286 }
TrailObject::hasTrail
bool hasTrail() const
Definition: trailobject.h:46
KSPlanetBase::setRearth
void setRearth(double r)
Set the distance from Earth, in AU.
Definition: ksplanetbase.h:139
KSPlanetBase::findPhase
virtual void findPhase()
Determine the phase of the planet.
Definition: ksplanetbase.cpp:277
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
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
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
KSSun
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition: kssun.h:31
TrailObject::clipTrail
void clipTrail()
removes the oldest point from the trail
Definition: trailobject.cpp:59
KSPlanetBase::JUPITER
Definition: ksplanetbase.h:82
KSPlanetBase::MOON
Definition: ksplanetbase.h:82
SkyPoint::findEcliptic
void findEcliptic(const dms *Obliquity, dms &EcLong, dms &EcLat)
Determine the Ecliptic coordinates of the SkyPoint, given the Julian Date.
Definition: skypoint.cpp:137
KSPlanetBase::helEcLat
const dms & helEcLat() const
Definition: ksplanetbase.h:110
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
KSPlanetBase::findGeocentricPosition
virtual bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth=NULL)=0
find the object's current geocentric equatorial coordinates (RA and Dec) This function is pure virtua...
SkyObject::setLongName
void setLongName(const QString &longname=QString())
Set the object's long name.
Definition: skyobject.cpp:92
KSPlanetBase::m_image
QImage m_image
Definition: ksplanetbase.h:245
KSPlanetBase::EquatorialToEcliptic
void EquatorialToEcliptic(const dms *Obliquity)
Convert Right Ascension/Declination to Ecliptic logitude/latitude.
Definition: ksplanetbase.cpp:97
EclipticPosition::latitude
dms latitude
Definition: ksplanetbase.h:43
KSPlanetBase::MERCURY
Definition: ksplanetbase.h:82
TextureManager::getImage
static const QImage & getImage(const QString &name)
Return texture image.
Definition: texturemanager.cpp:44
SkyObject::COMET
Definition: skyobject.h:110
ksplanet.h
KSPlanetBase::UID_SOL_BIGOBJ
static const UID UID_SOL_BIGOBJ
Big object.
Definition: ksplanetbase.h:203
KSPlanetBase::physicalSize
double physicalSize() const
Definition: ksplanetbase.h:179
KSPlanetBase::createPlanet
static KSPlanetBase * createPlanet(int n)
Definition: ksplanetbase.cpp:73
texturemanager.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
kspluto.h
TrailObject::Trail
QList< SkyPoint > Trail
Definition: trailobject.h:72
KSPlanetBase::Phase
double Phase
Definition: ksplanetbase.h:244
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
AU_KM
#define AU_KM
Definition: kstarsdata.h:42
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
TrailObject::addToTrail
void addToTrail()
adds a point to the planet's trail
Definition: trailobject.cpp:54
skymapcomposite.h
KSPlanetBase::setPA
void setPA(double p)
Set the Planet's position angle.
Definition: ksplanetbase.h:168
KSPlanetBase::UID_SOL_COMET
static const UID UID_SOL_COMET
Comets.
Definition: ksplanetbase.h:207
KSComet::setTailAngSize
void setTailAngSize(double tailangsize)
Sets the comet's apparent tail length in degrees.
Definition: kscomet.h:128
KSPlanetBase::angSize
double angSize() const
Definition: ksplanetbase.h:171
KSComet
A subclass of KSPlanetBase that implements comets.
Definition: kscomet.h:50
SkyMapComposite::earth
KSPlanet * earth()
Definition: skymapcomposite.cpp:581
KSPlanetBase::MARS
Definition: ksplanetbase.h:82
skymap.h
KSPlanetBase::rsun
double rsun() const
Definition: ksplanetbase.h:126
KSPlanetBase::KSPlanetBase
KSPlanetBase(const QString &s=i18n("unnamed"), const QString &image_file=QString(), const QColor &c=Qt::white, double pSize=0)
Constructor.
Definition: ksplanetbase.cpp:57
SkyObject::UID
qint64 UID
Type for Unique object IDenticator.
Definition: skyobject.h:53
ksnumbers.h
KSPlanetBase::isMajorPlanet
bool isMajorPlanet() const
Definition: ksplanetbase.cpp:151
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
SkyPoint::setFromEcliptic
void setFromEcliptic(const dms *Obliquity, const dms &EcLong, const dms &EcLat)
Set the current (RA, Dec) coordinates of the SkyPoint, given pointers to its Ecliptic (Long...
Definition: skypoint.cpp:151
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
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
EclipticPosition::longitude
dms longitude
Definition: ksplanetbase.h:42
KSPlanetBase::SATURN
Definition: ksplanetbase.h:82
KSPlanetBase::labelOffset
virtual double labelOffset() const
Definition: ksplanetbase.cpp:258
Options.h
KSPlanetBase::ecLat
const dms & ecLat() const
Definition: ksplanetbase.h:94
KSPlanetBase::helEcLong
const dms & helEcLong() const
Definition: ksplanetbase.h:107
KSPlanetBase::PLUTO
Definition: ksplanetbase.h:82
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
kssun.h
KSMoon
A subclass of SkyObject that provides information needed for the Moon.
Definition: ksmoon.h:36
SkyObject::type
int type(void) const
Definition: skyobject.h:164
kscomet.h
KSPlanetBase::rearth
double rearth() const
Definition: ksplanetbase.h:134
PI
#define PI
Definition: satellite.cpp:43
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
TrailObject
provides a SkyObject with an attachable Trail
Definition: trailobject.h:33
KSPlanetBase::pa
virtual double pa() const
Definition: ksplanetbase.h:163
ksmoon.h
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
SkyObject::ASTEROID
Definition: skyobject.h:110
KSPlanetBase::Rearth
double Rearth
Definition: ksplanetbase.h:243
SkyPoint::setRA
void setRA(dms r)
Sets RA, the current Right Ascension.
Definition: skypoint.h:119
ksasteroid.h
KSPlanetBase::SUN
Definition: ksplanetbase.h:82
SkyPoint::setDec
void setDec(dms d)
Sets Dec, the current Declination.
Definition: skypoint.h:130
kstarsdata.h
SkyObject::setName
void setName(const QString &name)
Set the object's primary name.
Definition: skyobject.h:419
dms::setD
void setD(const double &x)
Sets floating-point value of angle, in degrees.
Definition: dms.h:130
KSPlanetBase::setAngularSize
void setAngularSize(double size)
set the planet's angular size, in km.
Definition: ksplanetbase.h:176
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
KSPlanetBase::UID_SOL_ASTEROID
static const UID UID_SOL_ASTEROID
Asteroids.
Definition: ksplanetbase.h:205
KSPlanetBase::VENUS
Definition: ksplanetbase.h:82
KSPlanetBase::planetColor
static QVector< QColor > planetColor
Definition: ksplanetbase.h:86
ksutils.h
TrailObject::MaxTrail
static const int MaxTrail
Maximum trail size.
Definition: trailobject.h:70
KSPlanetBase::URANUS
Definition: ksplanetbase.h:82
KSPlanetBase::findMagnitude
virtual void findMagnitude(const KSNumbers *num)=0
Computes the visual magnitude for the major planets.
KSPlanetBase::phase
dms phase()
Definition: ksplanetbase.h:187
KSPluto
A subclass of KSAsteroid that represents the planet Pluto.
Definition: kspluto.h:43
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