• 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
kscomet.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  kscomet.cpp - K Desktop Planetarium
3  -------------------
4  begin : Wed 19 Feb 2003
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 "kscomet.h"
19 
20 #include <QRegExp>
21 #include <kdebug.h>
22 #include <QMap>
23 
24 #include "kstarsdata.h"
25 #include "kstarsdatetime.h"
26 #include "ksnumbers.h"
27 #include "dms.h"
28 
29 namespace {
30  int letterToNum(QChar c)
31  {
32  char l = c.toAscii();
33  if( l < 'A' || l > 'Z' || l == 'I')
34  return 0;
35  if( l > 'I' )
36  return l - 'A';
37  return l - 'A' + 1;
38  }
39  // Convert letter designation like "AZ" to number.
40  int letterDesigToN(QString s) {
41  int n = 0;
42  foreach(QChar c, s) {
43  int nl = letterToNum(c);
44  if( nl == 0 )
45  return 0;
46  n = n*25 + nl;
47  }
48  return n;
49  }
50 
51  QMap<QChar,qint64> cometType;
52 }
53 
54 KSComet::KSComet( const QString &_s, const QString &imfile,
55  long double _JD, double _q, double _e, dms _i, dms _w, dms _Node, double Tp, float _M1,
56  float _M2, float _K1, float _K2)
57  : KSPlanetBase(_s, imfile),
58  JD(_JD), q(_q), e(_e), M1(_M1), M2(_M2), K1(_K1), K2(_K2), i(_i), w(_w), N(_Node)
59 {
60  setType( SkyObject::COMET );
61 
62  //Find the Julian Day of Perihelion from Tp
63  //Tp is a double which encodes a date like: YYYYMMDD.DDDDD (e.g., 19730521.33333
64  int year = int( Tp/10000.0 );
65  int month = int( (int(Tp) % 10000)/100.0 );
66  int day = int( int(Tp) % 100 );
67  double Hour = 24.0 * ( Tp - int(Tp) );
68  int h = int( Hour );
69  int m = int( 60.0 * ( Hour - h ) );
70  int s = int( 60.0 * ( 60.0 * ( Hour - h) - m ) );
71 
72  JDp = KStarsDateTime( QDate( year, month, day ), QTime( h, m, s ) ).djd();
73 
74  //compute the semi-major axis, a:
75  a = q/(1.0-e);
76 
77  //Compute the orbital Period from Kepler's 3rd law:
78  P = 365.2568984 * pow(a, 1.5); //period in days
79 
80  //If the name contains a "/", make this name2 and make name a truncated version without the leading "P/" or "C/"
81  if ( name().contains( "/" ) ) {
82  setLongName( name() );
83  setName( name().mid( name().indexOf("/") + 1 ) );
84  }
85 
86  // Try to calculate UID for comets. It's derived from comet designation.
87  // To parge name string regular exressions are used. Not really readable.
88  // And its make strong assumtions about format of comets' names.
89  // Probably come better algotrithm should be used.
90 
91  // Periodic comet. Designation like: 12P or 12P-C
92  QRegExp rePer("^(\\d+)[PD](-([A-Z]+))?");
93  if( rePer.indexIn(_s) != -1 ) {
94  // Comet number
95  qint64 num = rePer.cap(1).toInt();
96  // Fragment number
97  qint64 fragmentN = letterDesigToN( rePer.cap(2) );
98  // Set UID
99  uidPart = num << 16 | fragmentN;
100  return;
101  }
102 
103  // Non periodic comet or comets with single approach
104  // Designations like C/(2006 A7)
105  QRegExp rePro("^([PCXDA])/.*\\((\\d{4}) ([A-Z])(\\d+)(-([A-Z]+))?\\)");
106  if( rePro.indexIn(_s) != -1 ) {
107  // Fill comet type
108  if( cometType.empty() ) {
109  cometType.insert('P',0);
110  cometType.insert('C',1);
111  cometType.insert('X',2);
112  cometType.insert('D',3);
113  cometType.insert('A',4);
114  }
115  qint64 type = cometType[ rePro.cap(1)[0] ]; // Type of comet
116  qint64 year = rePro.cap(2).toInt(); // Year of discovery
117  qint64 halfMonth = letterToNum( rePro.cap(3)[0] );
118  qint64 nHalfMonth = rePro.cap(4).toInt();
119  qint64 fragment = letterDesigToN( rePro.cap(6) );
120 
121  uidPart =
122  1 << 43 |
123  type << 40 | // Bits 40-42 (3)
124  halfMonth << 33 | // Bits 33-39 (7) Hope this is enough
125  nHalfMonth << 28 | // Bits 28-32 (5)
126  year << 16 | // Bits 16-27 (12)
127  fragment; // Bits 0-15 (16)
128  return;
129  }
130  uidPart = 0;
131  // kDebug() << "Didn't get it: " << _s;
132 }
133 
134 KSComet* KSComet::clone() const
135 {
136  return new KSComet(*this);
137 }
138 
139 void KSComet::findPhysicalParameters() {
140  // Compute and store the estimated Physical size of the comet's coma, tail and nucleus
141  // References:
142  // * http://www.projectpluto.com/update7b.htm#comet_tail_formula [Project Pluto / GUIDE]
143  // * http://articles.adsabs.harvard.edu//full/1978BAICz..29..103K/0000113.000.html [Kresak, 1978a, "Passages of comets and asteroids near the earth"]
144  NuclearSize = pow( 10, 2.1 - 0.2 * M1 );
145  double mHelio = M1 + K1 * log10( rsun() );
146  double L0, D0, L, D;
147  L0 = pow( 10, -0.0075 * mHelio * mHelio - 0.19 * mHelio + 2.10 );
148  D0 = pow( 10, -0.0033 * mHelio * mHelio - 0.07 * mHelio + 3.25 );
149  L = L0 * ( 1 - pow( 10, -4 * rsun() ) ) * ( 1 - pow( 10, -2 * rsun() ) );
150  D = D0 * ( 1 - pow( 10, -2 * rsun() ) ) * ( 1 - pow( 10, -rsun() ) );
151  TailSize = L * 1e6;
152  ComaSize = D * 1e3;
153  setPhysicalSize( ComaSize );
154 }
155 
156 bool KSComet::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
157  double v(0.0), r(0.0);
158 
159  //Precess the longitude of the Ascending Node to the desired epoch:
160  dms n = dms( double(N.Degrees() - 3.82394E-5 * ( num->julianDay() - J2000 )) ).reduce();
161 
162  if ( e > 0.98 ) {
163  //Use near-parabolic approximation
164  double k = 0.01720209895; //Gauss gravitational constant
165  double a = 0.75 * ( num->julianDay() - JDp ) * k * sqrt( (1+e)/(q*q*q) );
166  double b = sqrt( 1.0 + a*a );
167  double W = pow((b+a),1.0/3.0) - pow((b-a),1.0/3.0);
168  double c = 1.0 + 1.0/(W*W);
169  double f = (1.0-e)/(1.0+e);
170  double g = f/(c*c);
171 
172  double a1 = (2.0/3.0) + (2.0*W*W/5.0);
173  double a2 = (7.0/5.0) + (33.0*W*W/35.0) + (37.0*W*W*W*W/175.0);
174  double a3 = W*W*( (432.0/175.0) + (956.0*W*W/1125.0) + (84.0*W*W*W*W/1575.0) );
175  double w = W*(1.0 + g*c*( a1 + a2*g + a3*g*g ));
176 
177  v = 2.0*atan(w) / dms::DegToRad;
178  r = q*( 1.0 + w*w )/( 1.0 + w*w*f );
179  } else {
180  //Use normal ellipse method
181  //Determine Mean anomaly for desired date:
182  dms m = dms( double(360.0*( num->julianDay() - JDp )/P) ).reduce();
183  double sinm, cosm;
184  m.SinCos( sinm, cosm );
185 
186  //compute eccentric anomaly:
187  double E = m.Degrees() + e*180.0/dms::PI * sinm * ( 1.0 + e*cosm );
188 
189  if ( e > 0.05 ) { //need more accurate approximation, iterate...
190  double E0;
191  int iter(0);
192  do {
193  E0 = E;
194  iter++;
195  E = E0 - ( E0 - e*180.0/dms::PI *sin( E0*dms::DegToRad ) - m.Degrees() )/(1 - e*cos( E0*dms::DegToRad ) );
196  } while ( fabs( E - E0 ) > 0.001 && iter < 1000 );
197  }
198 
199  double sinE, cosE;
200  dms E1( E );
201  E1.SinCos( sinE, cosE );
202 
203  double xv = a * ( cosE - e );
204  double yv = a * sqrt( 1.0 - e*e ) * sinE;
205 
206  //v is the true anomaly; r is the distance from the Sun
207  v = atan2( yv, xv ) / dms::DegToRad;
208  r = sqrt( xv*xv + yv*yv );
209  }
210 
211  //vw is the sum of the true anomaly and the argument of perihelion
212  dms vw( v + w.Degrees() );
213  double sinN, cosN, sinvw, cosvw, sini, cosi;
214 
215  n.SinCos( sinN, cosN );
216  vw.SinCos( sinvw, cosvw );
217  i.SinCos( sini, cosi );
218 
219  //xh, yh, zh are the heliocentric cartesian coords with the ecliptic plane congruent with zh=0.
220  double xh = r * ( cosN * cosvw - sinN * sinvw * cosi );
221  double yh = r * ( sinN * cosvw + cosN * sinvw * cosi );
222  double zh = r * ( sinvw * sini );
223 
224  //the spherical ecliptic coordinates:
225  double ELongRad = atan2( yh, xh );
226  double ELatRad = atan2( zh, r );
227 
228  helEcPos.longitude.setRadians( ELongRad );
229  helEcPos.latitude.setRadians( ELatRad );
230  setRsun( r );
231 
232  //xe, ye, ze are the Earth's heliocentric cartesian coords
233  double cosBe, sinBe, cosLe, sinLe;
234  Earth->ecLong().SinCos( sinLe, cosLe );
235  Earth->ecLat().SinCos( sinBe, cosBe );
236 
237  double xe = Earth->rsun() * cosBe * cosLe;
238  double ye = Earth->rsun() * cosBe * sinLe;
239  double ze = Earth->rsun() * sinBe;
240 
241  //convert to geocentric ecliptic coordinates by subtracting Earth's coords:
242  xh -= xe;
243  yh -= ye;
244  zh -= ze;
245 
246  //Finally, the spherical ecliptic coordinates:
247  ELongRad = atan2( yh, xh );
248  double rr = sqrt( xh*xh + yh*yh );
249  ELatRad = atan2( zh, rr );
250 
251  ep.longitude.setRadians( ELongRad );
252  ep.latitude.setRadians( ELatRad );
253  setRearth( Earth );
254 
255  EclipticToEquatorial( num->obliquity() );
256  nutate( num );
257  aberrate( num );
258 
259  findPhysicalParameters();
260 
261  return true;
262 }
263 
264 //T-mag = M1 + 5*log10(delta) + k1*log10(r)
265 void KSComet::findMagnitude(const KSNumbers*)
266 {
267  setMag( M1 + 5.0 * log10( rearth() ) + K1 * log10( rsun() ) );
268 }
269 
270 void KSComet::setEarthMOID( double earth_moid )
271 {
272  EarthMOID = earth_moid;
273 }
274 
275 void KSComet::setAlbedo( float albedo )
276 {
277  Albedo = albedo;
278 }
279 
280 void KSComet::setDiameter( float diam )
281 {
282  Diameter = diam;
283 }
284 
285 void KSComet::setDimensions( QString dim )
286 {
287  Dimensions = dim;
288 }
289 
290 void KSComet::setNEO( bool neo )
291 {
292  NEO = neo;
293 }
294 
295 void KSComet::setOrbitClass( QString orbit_class )
296 {
297  OrbitClass = orbit_class;
298 }
299 
300 void KSComet::setOrbitID( QString orbit_id )
301 {
302  OrbitID = orbit_id;
303 }
304 
305 void KSComet::setPeriod( float per )
306 {
307  Period = per;
308 }
309 
310 void KSComet::setRotationPeriod(float rot_per)
311 {
312  RotationPeriod = rot_per;
313 }
314 
315 //Unused virtual function from KSPlanetBase
316 bool KSComet::loadData() { return false; }
317 
318 SkyObject::UID KSComet::getUID() const
319 {
320  return solarsysUID(UID_SOL_COMET) | uidPart;
321 }
KSPlanetBase::setRearth
void setRearth(double r)
Set the distance from Earth, in AU.
Definition: ksplanetbase.h:139
KSComet::findPhysicalParameters
void findPhysicalParameters()
Estimate physical parameters of the comet such as coma size, tail length and size of the nucleus...
Definition: kscomet.cpp:139
KSComet::setDiameter
void setDiameter(float diam)
Sets the comet's diameter.
Definition: kscomet.cpp:280
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
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyObject::setLongName
void setLongName(const QString &longname=QString())
Set the object's long name.
Definition: skyobject.cpp:92
KSPlanetBase::setRsun
void setRsun(double r)
Set the solar distance in AU.
Definition: ksplanetbase.h:131
KSComet::setPeriod
void setPeriod(float per)
Sets the comet's period.
Definition: kscomet.cpp:305
EclipticPosition::latitude
dms latitude
Definition: ksplanetbase.h:43
SkyObject::COMET
Definition: skyobject.h:110
KSComet::setEarthMOID
void setEarthMOID(double earth_moid)
Sets the comet's earth minimum orbit intersection distance.
Definition: kscomet.cpp:270
KSComet::setRotationPeriod
void setRotationPeriod(float rot_per)
Sets the comet's rotation period.
Definition: kscomet.cpp:310
KSComet::setOrbitClass
void setOrbitClass(QString orbit_class)
Sets the comet's orbit class.
Definition: kscomet.cpp:295
dms.h
NaN::f
const float f
Definition: nan.h:36
KSPlanetBase::ep
EclipticPosition ep
Definition: ksplanetbase.h:238
N
#define N(n)
Definition: RangeConvex.cpp:13
KSPlanetBase::solarsysUID
UID solarsysUID(UID type) const
Compute high 32-bits of UID.
Definition: ksplanetbase.h:210
KSPlanetBase::UID_SOL_COMET
static const UID UID_SOL_COMET
Comets.
Definition: ksplanetbase.h:207
KSPlanetBase::helEcPos
EclipticPosition helEcPos
Definition: ksplanetbase.h:242
KSComet
A subclass of KSPlanetBase that implements comets.
Definition: kscomet.h:50
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
KSPlanetBase::rsun
double rsun() const
Definition: ksplanetbase.h:126
KSComet::setOrbitID
void setOrbitID(QString orbit_id)
Sets the comet's orbit solution ID.
Definition: kscomet.cpp:300
SkyObject::UID
qint64 UID
Type for Unique object IDenticator.
Definition: skyobject.h:53
KSNumbers::julianDay
long double julianDay() const
Definition: ksnumbers.h:93
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
W
#define W(x)
Definition: SpatialIndex.cpp:42
ksnumbers.h
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
SkyObject::setType
void setType(int t)
Set the object's type identifier to the argument.
Definition: skyobject.h:171
EclipticPosition::longitude
dms longitude
Definition: ksplanetbase.h:42
KSPlanetBase::ecLat
const dms & ecLat() const
Definition: ksplanetbase.h:94
KSComet::loadData
virtual bool loadData()
Unused virtual function inherited from KSPlanetBase, so it's simply empty here.
Definition: kscomet.cpp:316
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
KSComet::KSComet
KSComet(const QString &s, const QString &image_file, long double JD, double q, double e, dms i, dms w, dms N, double Tp, float M1, float M2, float K1, float K2)
Constructor.
Definition: kscomet.cpp:54
SkyObject::type
int type(void) const
Definition: skyobject.h:164
kscomet.h
KSPlanetBase::rearth
double rearth() const
Definition: ksplanetbase.h:134
KSComet::setDimensions
void setDimensions(QString dim)
Sets the comet's dimensions.
Definition: kscomet.cpp:285
J2000
#define J2000
Definition: kstarsdatetime.h:21
PI
#define PI
Definition: satellite.cpp:43
KSComet::setAlbedo
void setAlbedo(float albedo)
Sets the comet's albedo.
Definition: kscomet.cpp:275
KSPlanetBase::setPhysicalSize
void setPhysicalSize(double size)
set the planet's physical size, in km.
Definition: ksplanetbase.h:184
KSComet::clone
virtual KSComet * clone() const
Create copy of object.
Definition: kscomet.cpp:134
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
kstarsdatetime.h
kstarsdata.h
SkyObject::setName
void setName(const QString &name)
Set the object's primary name.
Definition: skyobject.h:419
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
KSComet::getUID
virtual SkyObject::UID getUID() const
Return UID for object.
Definition: kscomet.cpp:318
KSComet::findGeocentricPosition
virtual bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth=NULL)
Calculate the geocentric RA, Dec coordinates of the Comet.
Definition: kscomet.cpp:156
KSComet::setNEO
void setNEO(bool neo)
Sets if the comet is a near earth object.
Definition: kscomet.cpp:290
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