Kstars

ksplanetbase.h
1/*
2 SPDX-FileCopyrightText: 2002 Mark Hollomon <mhh@mindspring.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "trailobject.h"
10#include "kstarsdata.h"
11
12#include <QColor>
13#include <QDebug>
14#include <QImage>
15#include <QList>
16
17class KSNumbers;
18
19/**
20 * @class EclipticPosition
21 * @short The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
22 * @author Mark Hollomon
23 * @version 1.0
24 */
26{
27 public:
28 dms longitude;
29 dms latitude;
30 double radius;
31
32 /**Constructor. */
33 explicit EclipticPosition(dms plong = dms(), dms plat = dms(), double prad = 0.0)
34 : longitude(plong), latitude(plat), radius(prad)
35 {
36 }
37};
38
39/**
40 * @class KSPlanetBase
41 * A subclass of TrailObject that provides additional information needed for most solar system
42 * objects. This is a base class for KSSun, KSMoon, KSPlanet, KSAsteroid and KSComet.
43 * Those classes cover all solar system objects except planetary moons, which are
44 * derived directly from TrailObject
45 * @short Provides necessary information about objects in the solar system.
46 * @author Mark Hollomon
47 * @version 1.0
48 */
50{
51 public:
52 /**
53 * Constructor. Calls SkyObject constructor with type=2 (planet),
54 * coordinates=0.0, mag=0.0, primary name s, and all other QStrings empty.
55 * @param s Name of planet
56 * @param image_file filename of the planet's image
57 * @param c color of the symbol to use for this planet
58 * @param pSize the planet's physical size, in km
59 */
60 explicit KSPlanetBase(const QString &s = i18n("unnamed"), const QString &image_file = QString(),
61 const QColor &c = Qt::white, double pSize = 0);
62
63 /** Destructor (empty) */
64 ~KSPlanetBase() override = default;
65
66 void init(const QString &s, const QString &image_file, const QColor &c, double pSize);
67
68 //enum Planets { MERCURY=0, VENUS=1, MARS=2, JUPITER=3, SATURN=4, URANUS=5, NEPTUNE=6, PLUTO=7, SUN=8, MOON=9, UNKNOWN_PLANET };
69 enum Planets
70 {
71 MERCURY = 0,
72 VENUS = 1,
73 MARS = 2,
74 JUPITER = 3,
75 SATURN = 4,
76 URANUS = 5,
77 NEPTUNE = 6,
78 SUN = 7,
79 MOON = 8,
80 EARTH_SHADOW = 9,
81 UNKNOWN_PLANET
82 };
83
84 static KSPlanetBase *createPlanet(int n);
85
86 static QVector<QColor> planetColor;
87
88 virtual bool loadData() = 0;
89
90 /** @return pointer to Ecliptic Longitude coordinate */
91 const dms &ecLong() const { return ep.longitude; }
92
93 /** @return pointer to Ecliptic Latitude coordinate */
94 const dms &ecLat() const { return ep.latitude; }
95
96 /**
97 * @short Set Ecliptic Geocentric Longitude according to argument.
98 * @param elong Ecliptic Longitude
99 */
100 void setEcLong(dms elong) { ep.longitude = elong; }
101
102 /**
103 * @short Set Ecliptic Geocentric Latitude according to argument.
104 * @param elat Ecliptic Latitude
105 */
106 void setEcLat(dms elat) { ep.latitude = elat; }
107
108 /** @return pointer to Ecliptic Heliocentric Longitude coordinate */
109 const dms &helEcLong() const { return helEcPos.longitude; }
110
111 /** @return pointer to Ecliptic Heliocentric Latitude coordinate */
112 const dms &helEcLat() const { return helEcPos.latitude; }
113
114 /**
115 * @short Convert Ecliptic longitude/latitude to Right Ascension/Declination.
116 * @param Obliquity current Obliquity of the Ecliptic (angle from Equator)
117 */
118 void EclipticToEquatorial(const CachingDms *Obliquity);
119
120 /**
121 * @short Convert Right Ascension/Declination to Ecliptic longitude/latitude.
122 * @param Obliquity current Obliquity of the Ecliptic (angle from Equator)
123 */
124 void EquatorialToEcliptic(const CachingDms *Obliquity);
125
126 /** @return pointer to this planet's texture */
127 const QImage &image() const { return m_image; }
128
129 /** @return distance from Sun, in Astronomical Units (1 AU is Earth-Sun distance) */
130 double rsun() const { return ep.radius; }
131
132 /**
133 * @short Set the solar distance in AU.
134 * @param r the new solar distance in AU
135 */
136 void setRsun(double r) { ep.radius = r; }
137
138 /** @return distance from Earth, in Astronomical Units (1 AU is Earth-Sun distance) */
139 double rearth() const { return Rearth; }
140
141 /**
142 * @short Set the distance from Earth, in AU.
143 * @param r the new earth-distance in AU
144 */
145 void setRearth(double r) { Rearth = r; }
146
147 /**
148 * @short compute and set the distance from Earth, in AU.
149 * @param Earth pointer to the Earth from which to calculate the distance.
150 */
151 void setRearth(const KSPlanetBase *Earth);
152
153 /**
154 * Update position of the planet (reimplemented from SkyPoint)
155 * @param num current KSNumbers object
156 * @param includePlanets this function does nothing if includePlanets=false
157 * @param lat pointer to the geographic latitude; if nullptr, we skip localizeCoords()
158 * @param LST pointer to the local sidereal time; if nullptr, we skip localizeCoords()
159 * @param forceRecompute defines whether the data should be recomputed forcefully
160 */
161 void updateCoords(const KSNumbers *num, bool includePlanets = true, const CachingDms *lat = nullptr,
162 const CachingDms *LST = nullptr, bool forceRecompute = false) override;
163
164 /**
165 * @short Find position, including correction for Figure-of-the-Earth.
166 * @param num KSNumbers pointer for the target date/time
167 * @param lat pointer to the geographic latitude; if nullptr, we skip localizeCoords()
168 * @param LST pointer to the local sidereal time; if nullptr, we skip localizeCoords()
169 * @param Earth pointer to the Earth (not used for the Moon)
170 */
171 void findPosition(const KSNumbers *num, const CachingDms *lat = nullptr, const CachingDms *LST = nullptr,
172 const KSPlanetBase *Earth = nullptr);
173
174 /** @return the Planet's position angle. */
175 double pa() const override { return PositionAngle; }
176
177 /**
178 * @short Set the Planet's position angle.
179 * @param p the new position angle
180 */
181 void setPA(double p) { PositionAngle = p; }
182
183 /** @return the Planet's angular size, in arcminutes */
184 double angSize() const { return AngularSize; }
185
186 /** @short set the planet's angular size, in km.
187 * @param size the planet's size, in km
188 */
189 void setAngularSize(double size) { AngularSize = size; }
190
191 /** @return the Planet's physical size, in km */
192 double physicalSize() const { return PhysicalSize; }
193
194 /** @short set the planet's physical size, in km.
195 * @param size the planet's size, in km
196 */
197 void setPhysicalSize(double size) { PhysicalSize = size; }
198
199 /** @return the phase angle of this planet */
200 inline dms phase() { return dms(Phase); }
201
202 /** @return the color for the planet symbol */
203 QColor &color() { return m_Color; }
204
205 /** @short Set the color for the planet symbol */
206 void setColor(const QColor &c) { m_Color = c; }
207
208 /** @return true if the KSPlanet is one of the eight major planets */
209 bool isMajorPlanet() const;
210
211 /** @return the pixel distance for offseting the object's name label */
212 double labelOffset() const override;
213
214 protected:
215 /** Big object. Planet, Moon, Sun. */
216 static const UID UID_SOL_BIGOBJ;
217 /** Asteroids */
218 static const UID UID_SOL_ASTEROID;
219 /** Comets */
220 static const UID UID_SOL_COMET;
221
222 /** Compute high 32-bits of UID. */
223 inline UID solarsysUID(UID type) const { return (SkyObject::UID_SOLARSYS << 60) | (type << 56); }
224
225 /**
226 * @short find the object's current geocentric equatorial coordinates (RA and Dec)
227 * This function is pure virtual; it must be overloaded by subclasses.
228 * This function is private; it is called by the public function findPosition()
229 * which also includes the figure-of-the-earth correction, localizeCoords().
230 * @param num pointer to current KSNumbers object
231 * @param Earth pointer to planet Earth (needed to calculate geocentric coords)
232 * @return true if position was successfully calculated.
233 */
234 virtual bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth = nullptr) = 0;
235
236 /**
237 * @short Computes the visual magnitude for the major planets.
238 * @param num pointer to a ksnumbers object. Needed for the saturn rings contribution to
239 * saturn's magnitude.
240 */
241 virtual void findMagnitude(const KSNumbers *num) = 0;
242
243 /**
244 * Determine the position angle of the planet for a given date
245 * (used internally by findPosition() )
246 */
247 void findPA(const KSNumbers *num);
248
249 /** Determine the phase of the planet. */
250 virtual void findPhase();
251
252 virtual double findAngularSize() { return asin(physicalSize() / Rearth / AU_KM) * 60. * 180. / dms::PI; }
253 // Geocentric ecliptic position, but distance to the Sun
255
256 // Heliocentric ecliptic position referred to the equinox of the epoch
257 // as obtained from VSOP.
258 EclipticPosition helEcPos;
259 double Rearth {NaN::d};
260 double Phase {NaN::d};
261 QImage m_image;
262
263 private:
264 /**
265 * @short correct the position for the fact that the location is not at the center of the Earth,
266 * but a position on its surface. This causes a small parallactic shift in a solar system
267 * body's apparent position. The effect is most significant for the Moon.
268 * This function is private, and should only be called from the public findPosition() function.
269 * @param num pointer to a ksnumbers object for the target date/time
270 * @param lat pointer to the geographic latitude of the location.
271 * @param LST pointer to the local sidereal time.
272 */
273 void localizeCoords(const KSNumbers *num, const CachingDms *lat, const CachingDms *LST);
274
275 double PositionAngle, AngularSize, PhysicalSize;
276 QColor m_Color;
277};
a dms subclass that caches its sine and cosine values every time the angle is changed.
Definition cachingdms.h:19
The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
EclipticPosition(dms plong=dms(), dms plat=dms(), double prad=0.0)
Constructor.
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
A subclass of TrailObject that provides additional information needed for most solar system objects.
virtual bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth=nullptr)=0
find the object's current geocentric equatorial coordinates (RA and Dec) This function is pure virtua...
UID solarsysUID(UID type) const
Compute high 32-bits of UID.
void findPosition(const KSNumbers *num, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, const KSPlanetBase *Earth=nullptr)
Find position, including correction for Figure-of-the-Earth.
void setPhysicalSize(double size)
set the planet's physical size, in km.
~KSPlanetBase() override=default
Destructor (empty)
const dms & helEcLat() const
static const UID UID_SOL_COMET
Comets.
static const UID UID_SOL_BIGOBJ
Big object.
const QImage & image() const
virtual void findMagnitude(const KSNumbers *num)=0
Computes the visual magnitude for the major planets.
static const UID UID_SOL_ASTEROID
Asteroids.
void setAngularSize(double size)
set the planet's angular size, in km.
void setRearth(double r)
Set the distance from Earth, in AU.
double physicalSize() const
KSPlanetBase(const QString &s=i18n("unnamed"), const QString &image_file=QString(), const QColor &c=Qt::white, double pSize=0)
Constructor.
void findPA(const KSNumbers *num)
Determine the position angle of the planet for a given date (used internally by findPosition() )
const dms & helEcLong() const
void updateCoords(const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, bool forceRecompute=false) override
Update position of the planet (reimplemented from SkyPoint)
double angSize() const
double labelOffset() const override
void setColor(const QColor &c)
Set the color for the planet symbol.
const dms & ecLat() const
void EquatorialToEcliptic(const CachingDms *Obliquity)
Convert Right Ascension/Declination to Ecliptic longitude/latitude.
void setEcLong(dms elong)
Set Ecliptic Geocentric Longitude according to argument.
const dms & ecLong() const
QColor & color()
double rearth() const
void EclipticToEquatorial(const CachingDms *Obliquity)
Convert Ecliptic longitude/latitude to Right Ascension/Declination.
double pa() const override
double rsun() const
void setEcLat(dms elat)
Set Ecliptic Geocentric Latitude according to argument.
virtual void findPhase()
Determine the phase of the planet.
void setRsun(double r)
Set the solar distance in AU.
void setPA(double p)
Set the Planet's position angle.
bool isMajorPlanet() const
qint64 UID
Type for Unique object IDenticator.
Definition skyobject.h:49
int type(void) const
Definition skyobject.h:188
provides a SkyObject with an attachable Trail
Definition trailobject.h:22
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition dms.h:385
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.