Kstars

approachsolver.h
1 /*
2  SPDX-FileCopyrightText: 2008 Akarsh Simha <[email protected]>
3  SPDX-FileCopyrightText: 2018 Valentin Boettcher <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #pragma once
9 #include "dms.h"
10 #include "skyobjects/ksplanet.h"
11 #include "skycomponents/typedef.h"
12 
13 #include <QObject>
14 #include <QMap>
15 #include <memory>
16 
17 /**
18  * @class ApproachSolver
19  * @short Implements algorithms to find close approaches of two objects on the sky.
20  * A class that implements a method to compute close approaches between any two solar system
21  * objects excluding planetary moons. Given two such objects, this class has implementations of
22  * algorithms required to find the time of closest approach in a given range of time. It is meant
23  * to be subclassed and provides the boilerplate (+ common interface) for classes like KSKonjunct
24  * and EclipseHandler.
25  *
26  * @author Akarsh Simha
27  * @version 2.0
28  */
29 class ApproachSolver : public QObject
30 {
31  Q_OBJECT
32 public:
33  explicit ApproachSolver(QObject *parent = nullptr);
34 
35  /**
36  * @short Sets the geographic location to compute conjunctions at
37  *
38  * @param geo Pointer to the GeoLocation object
39  */
40  void setGeoLocation(GeoLocation *geo);
41 
42  /**
43  * @short Compute the closest approach of two planets in the given range
44  *
45  * @param startJD Julian Day corresponding to start of the calculation period
46  * @param stopJD Julian Day corresponding to end of the calculation period
47  * @param callback A callback function
48  * @return Hash containing julian days of close conjunctions against separation
49  */
50  QMap<long double, dms> findClosestApproach(long double startJD,
51  long double stopJD,
52  const std::function<void (long double, dms)> &callback = {}); // FIXME: QMap is awkward!
53 
54  /**
55  * @brief getGeoLocation
56  * @return the currently set GeoLocation
57  */
58  GeoLocation * getGeoLocation() { return m_geoPlace; }
59 
60 
61  /**
62  * @brief setMaxSeparation
63  * @param sep - maximum allowed anglar separation
64  */
65  void setMaxSeparation(double sep) { m_maxSeparation = sep; }
66  void setMaxSeparation(dms sep) { m_maxSeparation = sep.radians(); }
67 
68 signals:
69  /**
70  * @brief solverMadeProgress
71  * @param progress - progress in percent
72  */
73  void solverMadeProgress(int progress);
74 
75 protected:
76  // TODO: This one may be moved to KSConjunct
77 
78  /**
79  * @brief getMaxSeparation
80  * @return the maximum separation allowed, based on the (guaranteed to be up-to-date)
81  * parameters of the objects if overwritten. Here it's just a constant.
82  */
83  virtual double getMaxSeparation() { return m_maxSeparation; }
84 
85  /**
86  * @brief findSkyPointDistance
87  * @param obj1
88  * @param obj2
89  * @return the angular distance between two SkyPoints in arcminutes
90  */
91  dms findSkyPointDistance(SkyPoint * obj1, SkyPoint * obj2);
92 
93  /**
94  * @short Finds the angular distance between two solar system objects.
95  * @return The angular distance between the two bodies.
96  */
97  virtual dms findDistance() = 0;
98 
99  /**
100  * @brief updatePositions
101  * @short Update the positions of the objects involved.
102  * @param jd Julian Day corresponding to the time of computation
103  */
104  virtual void updatePositions(long double jd) = 0;
105 
106  /**
107  * @brief findStep
108  * @return the step size used by findClosestApproach (in Julian Days)
109  *
110  * @short Make this as big as possible. The bigger it is, the more likely is a skip over...
111  */
112  virtual double findInitialStep(long double startJD, long double stopJD) = 0;
113 
114  /**
115  * @short Compute the precise value of the extremum once the extremum has been detected.
116  *
117  * @param out A pointer to a QPair that stores the Julian Day and Separation corresponding to the extremum
118  * @param jd Julian day corresponding to the endpoint of the interval where extremum was detected.
119  * @param step The step in jd taken during computation earlier. (Defines the interval size)
120  * @param prevSign The previous sign of increment in moving from jd - step to jd
121  *
122  * @return true if the extremum is a minimum
123  */
124  bool findPrecise(QPair<long double, dms> *out, long double jd,
125  double step, int prevSign);
126 
127  KSPlanet m_Earth;
128 
129 private:
130  /**
131  * @brief updateAndFindDistance
132  * @param jd Julian Date for which to calculate
133  * @return output of ApproachSolver::findDistance
134  */
135  dms updateAndFindDistance(long double jd) {
136  updatePositions(jd);
137  return findDistance();
138  }
139 
140  /**
141  * @short Return the sign of an angle
142  *
143  * @param a The angle whose sign has to be returned
144  *
145  * @return (-1, 0, 1) if a.radians() is (-ve, zero, +ve)
146  */
147  int sgn(dms a);
148 
149  GeoLocation * m_geoPlace { nullptr };
150  double m_maxSeparation;
151 };
Q_OBJECTQ_OBJECT
GeoLocation * getGeoLocation()
getGeoLocation
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
void solverMadeProgress(int progress)
solverMadeProgress
virtual dms findDistance()=0
Finds the angular distance between two solar system objects.
virtual double findInitialStep(long double startJD, long double stopJD)=0
findStep
Implements algorithms to find close approaches of two objects on the sky. A class that implements a m...
virtual void updatePositions(long double jd)=0
updatePositions
QMap< long double, dms > findClosestApproach(long double startJD, long double stopJD, const std::function< void(long double, dms)> &callback={})
Compute the closest approach of two planets in the given range.
Provides necessary information about objects in the solar system.
Definition: ksplanet.h:32
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
double radians() const
Express the angle in radians.
Definition: dms.h:320
bool findPrecise(QPair< long double, dms > *out, long double jd, double step, int prevSign)
Compute the precise value of the extremum once the extremum has been detected.
void setGeoLocation(GeoLocation *geo)
Sets the geographic location to compute conjunctions at.
virtual double getMaxSeparation()
getMaxSeparation
dms findSkyPointDistance(SkyPoint *obj1, SkyPoint *obj2)
findSkyPointDistance
void setMaxSeparation(double sep)
setMaxSeparation
QObject * parent() const const
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.