Kstars

approachsolver.h
1/*
2 SPDX-FileCopyrightText: 2008 Akarsh Simha <akarsh.simha@kdemail.net>
3 SPDX-FileCopyrightText: 2018 Valentin Boettcher <valentin@boettcher.cf>
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 */
29class ApproachSolver : public QObject
30{
32public:
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 */
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
69 /**
70 * @brief solverMadeProgress
71 * @param progress - progress in percent
72 */
73 void solverMadeProgress(int progress);
74
75protected:
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 */
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
129private:
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) {
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};
Implements algorithms to find close approaches of two objects on the sky.
virtual void updatePositions(long double jd)=0
updatePositions
virtual dms findDistance()=0
Finds the angular distance between two solar system objects.
void solverMadeProgress(int progress)
solverMadeProgress
dms findSkyPointDistance(SkyPoint *obj1, SkyPoint *obj2)
findSkyPointDistance
void setMaxSeparation(double sep)
setMaxSeparation
virtual double findInitialStep(long double startJD, long double stopJD)=0
findStep
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.
GeoLocation * getGeoLocation()
getGeoLocation
void setGeoLocation(GeoLocation *geo)
Sets the geographic location to compute conjunctions at.
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.
virtual double getMaxSeparation()
getMaxSeparation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition ksplanet.h:33
The sky coordinates of a point in the sky.
Definition skypoint.h:45
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.