File indexing completed on 2024-04-14 14:11:38

0001 /*
0002     SPDX-FileCopyrightText: 2008 Akarsh Simha <kstar@bas.org.in>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "ksconjunct.h"
0008 
0009 #include "ksnumbers.h"
0010 #include "kstarsdata.h"
0011 #include "skyobjects/skyobject.h"
0012 #include "skyobjects/ksplanetbase.h"
0013 
0014 #include <cmath>
0015 
0016 KSConjunct::KSConjunct() : ApproachSolver ()
0017 {
0018     connect(this, &ApproachSolver::solverMadeProgress, this, &KSConjunct::madeProgress);
0019 }
0020 
0021 dms KSConjunct::findDistance()
0022 {
0023     dms dist = findSkyPointDistance(m_object1.get(), m_object2.get());
0024     if (m_opposition)
0025     {
0026         dist.setD(180 - dist.Degrees());
0027     }
0028 
0029     return dist;
0030 }
0031 
0032 void KSConjunct::updatePositions(long double jd)
0033 {
0034     KStarsDateTime t(jd);
0035     KSNumbers num(jd);
0036 
0037     m_Earth.findPosition(&num);
0038     CachingDms LST(getGeoLocation()->GSTtoLST(t.gst()));
0039 
0040     KSPlanetBase *p = dynamic_cast<KSPlanetBase*>(m_object1.get());
0041     if (p)
0042         p->findPosition(&num, getGeoLocation()->lat(), &LST, &m_Earth);
0043     else
0044         m_object1->updateCoordsNow(&num);
0045 
0046     m_object2->findPosition(&num, getGeoLocation()->lat(), &LST, &m_Earth);
0047 }
0048 
0049 double KSConjunct::findInitialStep(long double startJD, long double stopJD)
0050 {
0051 
0052     double step0 =
0053         double(stopJD - startJD) / 4.0; // I'm an idiot for having done this without having the lines that follow -- asimha
0054 
0055     // TODO: Work out a solid footing on which one can decide step0. -- asimha
0056     if (step0 > 24.8 * 365.25) // Sample pluto's orbit (248.09 years) at least 10 times.
0057         step0 = 24.8 * 365.25;
0058 
0059     // FIXME: This can be done better, but for now, I'm doing it the dumb way -- asimha
0060     if (m_object1->name() == i18n("Neptune") || m_object2->name() == i18n("Neptune") || m_object1->name() == i18n("Uranus") ||
0061             m_object2->name() == i18n("Uranus"))
0062         if (step0 > 3652.5)
0063             step0 = 3652.5;
0064     if (m_object1->name() == i18n("Jupiter") || m_object2->name() == i18n("Jupiter") || m_object1->name() == i18n("Saturn") ||
0065             m_object2->name() == i18n("Saturn"))
0066         if (step0 > 365.25)
0067             step0 = 365;
0068     if (m_object1->name() == i18n("Mars") || m_object2->name() == i18n("Mars"))
0069         if (step0 > 10.0)
0070             step0 = 10.0;
0071     if (m_object1->name() == i18n("Venus") || m_object1->name() == i18n("Mercury") || m_object2->name() == i18n("Mercury") ||
0072             m_object2->name() == i18n("Venus"))
0073         if (step0 > 5.0)
0074             step0 = 5.0;
0075     if (m_object1->name() == i18n("Moon") || m_object2->name() == i18n("Moon"))
0076         if (step0 > 0.25)
0077             step0 = 0.25;
0078 
0079     return step0;
0080 }