1 /*
2 SPDX-FileCopyrightText: 2008 Akarsh Simha <kstar@bas.org.in>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "ksconjunct.h"
8
9 #include "ksnumbers.h"
10 #include "kstarsdata.h"
11 #include "skyobjects/skyobject.h"
12 #include "skyobjects/ksplanetbase.h"
13
14 #include <cmath>
15
KSConjunct()16 KSConjunct::KSConjunct() : ApproachSolver ()
17 {
18 connect(this, &ApproachSolver::solverMadeProgress, this, &KSConjunct::madeProgress);
19 }
20
findDistance()21 dms KSConjunct::findDistance()
22 {
23 dms dist = findSkyPointDistance(m_object1.get(), m_object2.get());
24 if (m_opposition)
25 {
26 dist.setD(180 - dist.Degrees());
27 }
28
29 return dist;
30 }
31
updatePositions(long double jd)32 void KSConjunct::updatePositions(long double jd)
33 {
34 KStarsDateTime t(jd);
35 KSNumbers num(jd);
36
37 m_Earth.findPosition(&num);
38 CachingDms LST(getGeoLocation()->GSTtoLST(t.gst()));
39
40 KSPlanetBase *p = dynamic_cast<KSPlanetBase*>(m_object1.get());
41 if (p)
42 p->findPosition(&num, getGeoLocation()->lat(), &LST, &m_Earth);
43 else
44 m_object1->updateCoordsNow(&num);
45
46 m_object2->findPosition(&num, getGeoLocation()->lat(), &LST, &m_Earth);
47 }
48
findInitialStep(long double startJD,long double stopJD)49 double KSConjunct::findInitialStep(long double startJD, long double stopJD)
50 {
51
52 double step0 =
53 double(stopJD - startJD) / 4.0; // I'm an idiot for having done this without having the lines that follow -- asimha
54
55 // TODO: Work out a solid footing on which one can decide step0. -- asimha
56 if (step0 > 24.8 * 365.25) // Sample pluto's orbit (248.09 years) at least 10 times.
57 step0 = 24.8 * 365.25;
58
59 // FIXME: This can be done better, but for now, I'm doing it the dumb way -- asimha
60 if (m_object1->name() == i18n("Neptune") || m_object2->name() == i18n("Neptune") || m_object1->name() == i18n("Uranus") ||
61 m_object2->name() == i18n("Uranus"))
62 if (step0 > 3652.5)
63 step0 = 3652.5;
64 if (m_object1->name() == i18n("Jupiter") || m_object2->name() == i18n("Jupiter") || m_object1->name() == i18n("Saturn") ||
65 m_object2->name() == i18n("Saturn"))
66 if (step0 > 365.25)
67 step0 = 365;
68 if (m_object1->name() == i18n("Mars") || m_object2->name() == i18n("Mars"))
69 if (step0 > 10.0)
70 step0 = 10.0;
71 if (m_object1->name() == i18n("Venus") || m_object1->name() == i18n("Mercury") || m_object2->name() == i18n("Mercury") ||
72 m_object2->name() == i18n("Venus"))
73 if (step0 > 5.0)
74 step0 = 5.0;
75 if (m_object1->name() == i18n("Moon") || m_object2->name() == i18n("Moon"))
76 if (step0 > 0.25)
77 step0 = 0.25;
78
79 return step0;
80 }
81