Kstars

kssun.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
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
17KSSun::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
35void 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
152double KSSun::nightFraction()
153{
154 constexpr double FULL_NIGHTTIME_DEGREES = -18.0;
155 KStarsData *data = KStarsData::Instance();
156 if (!data) return 1.0;
157
158 EquatorialToHorizontal(data->lst(), data->geo()->lat());
159 const double sunAltitudeDegrees = alt().Degrees();
160 double nightFraction = 1.0;
161 if (sunAltitudeDegrees > 0)
162 nightFraction = 0.0;
163 else if (sunAltitudeDegrees < 0 && sunAltitudeDegrees > FULL_NIGHTTIME_DEGREES)
164 nightFraction = sunAltitudeDegrees / FULL_NIGHTTIME_DEGREES;
165 return nightFraction;
166}
167
169{
170 return solarsysUID(UID_SOL_BIGOBJ) | 0;
171}
The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
const CachingDms * lat() const
Definition geolocation.h:70
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
const CachingDms * obliquity() const
Definition ksnumbers.h:56
double julianMillenia() const
Definition ksnumbers.h:94
A subclass of TrailObject that provides additional information needed for most solar system objects.
UID solarsysUID(UID type) const
Compute high 32-bits of UID.
static const UID UID_SOL_BIGOBJ
Big object.
void setRearth(double r)
Set the distance from Earth, in AU.
void findPA(const KSNumbers *num)
Determine the position angle of the planet for a given date (used internally by findPosition() )
void EquatorialToEcliptic(const CachingDms *Obliquity)
Convert Right Ascension/Declination to Ecliptic longitude/latitude.
void setEcLong(dms elong)
Set Ecliptic Geocentric Longitude according to argument.
void EclipticToEquatorial(const CachingDms *Obliquity)
Convert Ecliptic longitude/latitude to Right Ascension/Declination.
double rsun() const
void setEcLat(dms elat)
Set Ecliptic Geocentric Latitude according to argument.
OrbitDataColl contains three groups of six QVectors.
Definition ksplanet.h:122
bool loadData(OrbitDataColl &odc, const QString &n)
Load orbital data for a planet from disk.
Definition ksplanet.cpp:56
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition ksplanet.h:33
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
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
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
KSSun()
Constructor.
Definition kssun.cpp:17
bool loadData() override
Read orbital data from disk.
Definition kssun.cpp:28
KSSun * clone() const override
Create copy of object.
Definition kssun.cpp:22
SkyObject::UID getUID() const override
Return UID for object.
Definition kssun.cpp:168
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
GeoLocation * geo()
Definition kstarsdata.h:230
void setMag(float m)
Set the object's sorting magnitude.
Definition skyobject.h:403
qint64 UID
Type for Unique object IDenticator.
Definition skyobject.h:49
void aberrate(const KSNumbers *num, bool reverse=false)
Determine the effects of aberration for this SkyPoint.
Definition skypoint.cpp:454
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra() const
Definition skypoint.h:263
void precess(const KSNumbers *num)
Precess this SkyPoint's catalog coordinates to the epoch described by the given KSNumbers object.
Definition skypoint.cpp:223
void nutate(const KSNumbers *num, const bool reverse=false)
Apply the effects of nutation to this SkyPoint.
Definition skypoint.cpp:275
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition skypoint.cpp:77
void setRA0(dms r)
Sets RA0, the catalog Right Ascension.
Definition skypoint.h:94
const dms & alt() const
Definition skypoint.h:281
void setDec0(dms d)
Sets Dec0, the catalog Declination.
Definition skypoint.h:119
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
Definition dms.cpp:251
virtual void setRadians(const double &Rad)
Set angle according to the argument, in radians.
Definition dms.h:333
const double & Degrees() const
Definition dms.h:141
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.