Kstars

kssun.cpp
1 /*
2  SPDX-FileCopyrightText: 2001 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "kssun.h"
8 
9 #include <typeinfo>
10 
11 #include <cmath>
12 
13 #include "ksnumbers.h"
14 #include "kstarsdata.h"
15 #include "kstarsdatetime.h"
16 
17 KSSun::KSSun() : KSPlanet(i18n("Sun"), "sun", Qt::yellow, 1392000. /*diameter in km*/)
18 {
19  setMag(-26.73);
20 }
21 
23 {
24  Q_ASSERT(typeid(this) == typeid(static_cast<const KSSun *>(this))); // Ensure we are not slicing a derived class
25  return new KSSun(*this);
26 }
27 
29 {
30  OrbitDataColl odc;
31  return (odm.loadData(odc, "earth") != 0);
32 }
33 
34 // We don't need to do anything here
35 void KSSun::findMagnitude(const KSNumbers *)
36 {
37 }
38 
40 {
41  if (Earth)
42  {
43  //
44  // For the precision we need, the earth's orbit is circular.
45  // So don't bother to iterate like KSPlanet does. Just subtract
46  // The current delay and recompute (once).
47  //
48 
49  //The light-travel time delay, in millenia
50  //0.0057755183 is the inverse speed of light, in days/AU
51  double delay = (.0057755183 * Earth->rsun()) / 365250.0;
52  //
53  // MHH 2002-02-04 I don't like this. But it avoids code duplication.
54  // Maybe we can find a better way.
55  //
56  const KSPlanet *pEarth = static_cast<const KSPlanet *>(Earth);
57  EclipticPosition trialpos;
58  pEarth->calcEcliptic(num->julianMillenia() - delay, trialpos);
59 
60  setEcLong((trialpos.longitude + dms(180.0)).reduce());
61  setEcLat(-trialpos.latitude);
62 
63  setRearth(Earth->rsun());
64  }
65  else
66  {
67  double sum[6];
68  dms EarthLong, EarthLat; //heliocentric coords of Earth
69  OrbitDataColl odc;
70  double T = num->julianMillenia(); //Julian millenia since J2000
71  double Tpow[6];
72 
73  Tpow[0] = 1.0;
74  for (int i = 1; i < 6; ++i)
75  {
76  Tpow[i] = Tpow[i - 1] * T;
77  }
78  //First, find heliocentric coordinates
79 
80  if (!odm.loadData(odc, "earth"))
81  return false;
82 
83  //Ecliptic Longitude
84  for (int i = 0; i < 6; ++i)
85  {
86  sum[i] = 0.0;
87  for (int j = 0; j < odc.Lon[i].size(); ++j)
88  {
89  sum[i] += odc.Lon[i][j].A * cos(odc.Lon[i][j].B + odc.Lon[i][j].C * T);
90  }
91  sum[i] *= Tpow[i];
92  //qDebug() << Q_FUNC_INFO << name() << " : sum[" << i << "] = " << sum[i];
93  }
94 
95  EarthLong.setRadians(sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5]);
96  EarthLong = EarthLong.reduce();
97 
98  //Compute Ecliptic Latitude
99  for (int i = 0; i < 6; ++i)
100  {
101  sum[i] = 0.0;
102  for (int j = 0; j < odc.Lat[i].size(); ++j)
103  {
104  sum[i] += odc.Lat[i][j].A * cos(odc.Lat[i][j].B + odc.Lat[i][j].C * T);
105  }
106  sum[i] *= Tpow[i];
107  }
108 
109  EarthLat.setRadians(sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5]);
110 
111  //Compute Heliocentric Distance
112  for (int i = 0; i < 6; ++i)
113  {
114  sum[i] = 0.0;
115  for (int j = 0; j < odc.Dst[i].size(); ++j)
116  {
117  sum[i] += odc.Dst[i][j].A * cos(odc.Dst[i][j].B + odc.Dst[i][j].C * T);
118  }
119  sum[i] *= Tpow[i];
120  }
121 
122  ep.radius = sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5];
123  setRearth(ep.radius);
124 
125  setEcLong((EarthLong + dms(180.0)).reduce());
126  setEcLat(-EarthLat);
127  }
128 
129  //Finally, convert Ecliptic coords to Ra, Dec. Ecliptic latitude is zero, by definition
131 
132  nutate(num);
133 
134  // Store in RA0 and Dec0, the unaberrated coordinates
135  setRA0(ra());
136  setDec0(dec());
137 
138  precess(num);
139 
140  aberrate(num);
141 
142  // We obtain the apparent geocentric ecliptic coordinates. That is, after
143  // nutation and aberration have been applied.
145 
146  //Determine the position angle
147  findPA(num);
148 
149  return true;
150 }
151 
153 {
154  return solarsysUID(UID_SOL_BIGOBJ) | 0;
155 }
bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth=nullptr) override
Determine geocentric RA, Dec coordinates for the Epoch given in the argument.
Definition: kssun.cpp:39
OrbitDataColl contains three groups of six QVectors.
Definition: ksplanet.h:121
double julianMillenia() const
Definition: ksnumbers.h:94
void setDec0(dms d)
Sets Dec0, the catalog Declination.
Definition: skypoint.h:119
double rsun() const
Definition: ksplanetbase.h:130
KSSun()
Constructor.
Definition: kssun.cpp:17
KSSun * clone() const override
Create copy of object.
Definition: kssun.cpp:22
void setEcLat(dms elat)
Set Ecliptic Geocentric Latitude according to argument.
Definition: ksplanetbase.h:106
void setRA0(dms r)
Sets RA0, the catalog Right Ascension.
Definition: skypoint.h:94
qint64 UID
Type for Unique object IDenticator.
Definition: skyobject.h:49
void setEcLong(dms elong)
Set Ecliptic Geocentric Longitude according to argument.
Definition: ksplanetbase.h:100
Provides necessary information about the Sun.
Definition: kssun.h:23
The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
Definition: ksplanetbase.h:25
QString i18n(const char *text, const TYPE &arg...)
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms & dec() const
Definition: skypoint.h:269
void setMag(float m)
Set the object's sorting magnitude.
Definition: skyobject.h:403
void setRearth(double r)
Set the distance from Earth, in AU.
Definition: ksplanetbase.h:145
SkyObject::UID getUID() const override
Return UID for object.
Definition: kssun.cpp:152
bool loadData(OrbitDataColl &odc, const QString &n)
Load orbital data for a planet from disk.
Definition: ksplanet.cpp:56
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:192
Provides necessary information about objects in the solar system.
Definition: ksplanet.h:32
void precess(const KSNumbers *num)
Precess this SkyPoint's catalog coordinates to the epoch described by the given KSNumbers object.
Definition: skypoint.cpp:223
UID solarsysUID(UID type) const
Compute high 32-bits of UID.
Definition: ksplanetbase.h:223
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
virtual void setRadians(const double &Rad)
Set angle according to the argument, in radians.
Definition: dms.h:328
bool loadData() override
Read orbital data from disk.
Definition: kssun.cpp:28
const CachingDms & ra() const
Definition: skypoint.h:263
const CachingDms * obliquity() const
Definition: ksnumbers.h:56
void EquatorialToEcliptic(const CachingDms *Obliquity)
Convert Right Ascension/Declination to Ecliptic longitude/latitude.
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
Definition: dms.cpp:251
void EclipticToEquatorial(const CachingDms *Obliquity)
Convert Ecliptic longitude/latitude to Right Ascension/Declination.
void aberrate(const KSNumbers *num, bool reverse=false)
Determine the effects of aberration for this SkyPoint.
Definition: skypoint.cpp:454
void nutate(const KSNumbers *num, const bool reverse=false)
Apply the effects of nutation to this SkyPoint.
Definition: skypoint.cpp:275
static const UID UID_SOL_BIGOBJ
Big object.
Definition: ksplanetbase.h:216
void findPA(const KSNumbers *num)
Determine the position angle of the planet for a given date (used internally by findPosition() )
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Aug 17 2022 04:14:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.