Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions plugins/NavStars/src/gui/NavStarsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ void NavStarsWindow::populateToday()

// Moon
Vec4d moon = GETSTELMODULE(SolarSystem)->getMoon()->getRTSTime(core, 0.);
if (moon[3]==0.)
{
if (moon[3]==30 || moon[3]<0 || moon[3]>50) // no moonrise on current date
moonrise = dash;
else
moonrise = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(moon[0]+utcShift), true);
moonset = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(moon[2]+utcShift), true);
}

if (moon[3]==40 || moon[3]<0 || moon[3]>50) // no moonset on current date
moonset = dash;
else
moonrise = moonset = dash;
moonset = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(moon[2]+utcShift), true);

// day
Vec4d day = sun->getRTSTime(core, 0.);
Expand Down
118 changes: 101 additions & 17 deletions src/core/StelObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Vec4d StelObject::getRTSTime(const StelCore *core, const double altitude) const
const double rotRate = obsPlanet->getSiderealDay();
const double currentJD=core->getJD();
const double currentJDE=core->getJDE();
const double utcShift = core->getUTCOffset(currentJD) / 24.;
int year, month, day, currentdate;
StelUtils::getDateFromJulianDay(currentJD+utcShift, &year, &month, &currentdate);

// And convert to equatorial coordinates of date. We can also use this day's current aberration, given the other uncertainties/omissions.
const Vec3d eq_2=getEquinoxEquatorialPos(core);
Expand Down Expand Up @@ -206,6 +209,15 @@ Vec4d StelObject::getRTSTime(const StelCore *core, const double altitude) const

double mr, ms, flag=0.;
double mt=-h2*(0.5*rotRate/M_PI);
// Transit should occur on current date
StelUtils::getDateFromJulianDay(currentJD+mt+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (mt<0.)
mt += rotRate;
else
mt -= rotRate;
}

// circumpolar: set rise and set times to lower culmination, i.e. 1/2 rotation from transit
if (fabs(cosH0)>1.)
Expand All @@ -223,6 +235,26 @@ Vec4d StelObject::getRTSTime(const StelCore *core, const double altitude) const
ms = mt + H0*rotRate/(2.*M_PI);
}

// Rise should occur on current date
StelUtils::getDateFromJulianDay(currentJD+mr+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (mr<0.)
mr += rotRate;
else
mr -= rotRate;
}

// Set should occur on current date
StelUtils::getDateFromJulianDay(currentJD+ms+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (ms<0.)
ms += rotRate;
else
ms -= rotRate;
}

//omgr->addToExtraInfoString(StelObject::DebugAid, QString("m<sub>t</sub>= %1<br/>").arg(QString::number(mt, 'f', 6)));
//omgr->addToExtraInfoString(StelObject::DebugAid, QString("m<sub>r</sub>= %1<br/>").arg(QString::number(mr, 'f', 6)));
//omgr->addToExtraInfoString(StelObject::DebugAid, QString("m<sub>s</sub>= %1<br/>").arg(QString::number(ms, 'f', 6)));
Expand Down Expand Up @@ -677,20 +709,34 @@ QString StelObject::getCommonInfoString(const StelCore *core, const InfoStringGr

if (flags&RTSTime && getType()!=QStringLiteral("Satellite") && !currentPlanet.contains("observer", Qt::CaseInsensitive) && !(core->getCurrentLocation().name.contains("->")))
{
const double utcShift = core->getUTCOffset(core->getJD()) / 24.; // Fix DST shift...
const double currentJD = core->getJD();
const double utcShift = core->getUTCOffset(currentJD) / 24.; // Fix DST shift...
Vec4d rts = getRTSTime(core);
QString sTransit = qc_("Transit", "celestial event; passage across a meridian");
QString sRise = qc_("Rise", "celestial event");
QString sSet = qc_("Set", "celestial event");
const QString dash = QChar(0x2014);
double sunrise = 0.;
double sunset = 24.;
const bool isSun = (getEnglishName()=="Sun");
const bool isSun = (getEnglishName()=="Sun");
double hour(0);

int year, month, day, currentdate;
StelUtils::getDateFromJulianDay(currentJD+utcShift, &year, &month, &currentdate);

if (withTables && !(flags&SiderealTime && currentPlanet==QStringLiteral("Earth")))
res += "<table style='margin:0em 0em 0em -0.125em;border-spacing:0px;border:0px;'>";

if (rts[3]==0.)
// Rise
StelUtils::getDateFromJulianDay(rts[0]+utcShift, &year, &month, &day);
if (rts[3]==30 || rts[3]<0 || rts[3]>50 || day != currentdate) // no rise
{
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sRise, dash);
else
res += QString("%1: %2<br/>").arg(sRise, dash);
}
else
{
hour = StelUtils::getHoursFromJulianDay(rts[0]+utcShift);
if (withTables)
Expand All @@ -701,14 +747,34 @@ QString StelObject::getCommonInfoString(const StelCore *core, const InfoStringGr
sunrise = hour;
}

hour = StelUtils::getHoursFromJulianDay(rts[1]+utcShift);
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sTransit, StelUtils::hoursToHmsStr(hour, true));
else
res += QString("%1: %2<br/>").arg(sTransit, StelUtils::hoursToHmsStr(hour, true));
// Transit
StelUtils::getDateFromJulianDay(rts[1]+utcShift, &year, &month, &day);
if (rts[3]==20 || day != currentdate) // no transit
{
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sTransit, dash);
else
res += QString("%1: %2<br/>").arg(sTransit, dash);
}
else {
hour = StelUtils::getHoursFromJulianDay(rts[1]+utcShift);

if (rts[3]==0.)
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sTransit, StelUtils::hoursToHmsStr(hour, true));
else
res += QString("%1: %2<br/>").arg(sTransit, StelUtils::hoursToHmsStr(hour, true));
}

// Set
StelUtils::getDateFromJulianDay(rts[2]+utcShift, &year, &month, &day);
if (rts[3]==40 || rts[3]<0 || rts[3]>50 || day != currentdate) // no set
{
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sSet, dash);
else
res += QString("%1: %2<br/>").arg(sSet, dash);
}
else {
hour = StelUtils::getHoursFromJulianDay(rts[2]+utcShift);
if (withTables)
res += QString("<tr><td>%1:</td><td style='text-align:right;'>%2</td></tr>").arg(sSet, StelUtils::hoursToHmsStr(hour, true));
Expand Down Expand Up @@ -760,7 +826,7 @@ QString StelObject::getCommonInfoString(const StelCore *core, const InfoStringGr
else
res += q_("This object never rises") + "<br />";
}
else if (rts[3]>0.)
else if (rts[3]>50.)
{
if (isSun)
res += q_("Polar day") + "<br />";
Expand Down Expand Up @@ -1053,23 +1119,41 @@ QVariantMap StelObject::getInfoMap(const StelCore *core) const
StelUtils::getTimeFromJulianDay(rts[1]+utcShift, &hr, &min, &sec);
double hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;

map.insert("transit", StelUtils::hoursToHmsStr(hours, true));
map.insert("transit-dhr", hours);
if (rts[3]==0.)
int year, month, day, currentdate;
StelUtils::getDateFromJulianDay(core->getJD()+utcShift, &year, &month, &currentdate);
StelUtils::getDateFromJulianDay(rts[1]+utcShift, &year, &month, &day);
if (rts[3]==20 || day != currentdate) // no transit
{
map.insert("transit", "---");
}
else {
map.insert("transit", StelUtils::hoursToHmsStr(hours, true));
map.insert("transit-dhr", hours);
}

StelUtils::getDateFromJulianDay(rts[0]+utcShift, &year, &month, &day);
if (rts[3]==30 || rts[3]<0 || rts[3]>50 || day != currentdate) // no rise
{
map.insert("rise", "---");
}
else {
StelUtils::getTimeFromJulianDay(rts[0]+utcShift, &hr, &min, &sec);
hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;
map.insert("rise", StelUtils::hoursToHmsStr(hours, true));
map.insert("rise-dhr", hours);
}

StelUtils::getDateFromJulianDay(rts[2]+utcShift, &year, &month, &day);
if (rts[3]==40 || rts[3]<0 || rts[3]>50 || day != currentdate) // no set
{
map.insert("set", "---");
}
else {
StelUtils::getTimeFromJulianDay(rts[2]+utcShift, &hr, &min, &sec);
hours=hr+static_cast<double>(min)/60. + static_cast<double>(sec)/3600.;
map.insert("set", StelUtils::hoursToHmsStr(hours, true));
map.insert("set-dhr", hours);
}
else {
map.insert("rise", "---");
map.insert("set", "---");
}
}
return map;
}
Expand Down
100 changes: 99 additions & 1 deletion src/core/modules/Planet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4912,7 +4912,7 @@ void Planet::setApparentMagnitudeAlgorithm(QString algorithm)
// We don't compute positions for midnights, but only for two extra positions 1 JD before and after "now", to allow interpolation of positions.
// Also, the estimate h0 for the Moon in the literature is based on geocentric computation.
// NOTE: Limitation for efficiency: If this is a planet moon from another planet, we compute RTS for the parent planet instead!
Vec4d Planet::getRTSTime(const StelCore *core, const double altitude) const
Vec4d Planet::getClosestRTSTime(const StelCore *core, const double altitude) const
{
const StelLocation loc=core->getCurrentLocation();
if (loc.name.contains("->")) // a spaceship
Expand Down Expand Up @@ -5243,3 +5243,101 @@ Vec4d Planet::getRTSTime(const StelCore *core, const double altitude) const

return Vec4d(currentJD+mr, currentJD+mt, currentJD+ms, flag);
}

Vec4d Planet::getRTSTime(const StelCore *core, const double altitude) const
{
// Keep time in sync (method from line 592) to fix slow down of time when the moon is selected
const double currentJD = core->getJDOfLastJDUpdate();
const qint64 millis = core->getMilliSecondsOfLastJDUpdate();
const double utcShift = core->getUTCOffset(currentJD) / 24.;
StelCore* core1 = StelApp::getInstance().getCore();
Vec4d rts = getClosestRTSTime(core1,altitude);
int year, month, day, currentdate;
StelUtils::getDateFromJulianDay(currentJD+utcShift, &year, &month, &currentdate);
Vec4d rtsNew;

// Transit
StelUtils::getDateFromJulianDay(rts[1]+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (rts[1]<currentJD) // found time before current date
{
core1->setJD(rts[1]+1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[1] = rtsNew[1];
rts[3] = rtsNew[3];
}
else if (rts[1]>currentJD) // found time after current date
{
core1->setJD(rts[1]-1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[1] = rtsNew[1];
rts[3] = rtsNew[3];
}
}

// Rise
StelUtils::getDateFromJulianDay(rts[0]+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (rts[0]<currentJD) // found time before current date
{
core1->setJD(rts[0]+1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[0] = rtsNew[0];
rts[3] = rtsNew[3];
}
else if (rts[0]>currentJD) // found time after current date
{
core1->setJD(rts[0]-1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[0] = rtsNew[0];
rts[3] = rtsNew[3];
}
}

// Set
StelUtils::getDateFromJulianDay(rts[2]+utcShift, &year, &month, &day);
if (day != currentdate)
{
if (rts[2]<currentJD) // found time before current date
{
core1->setJD(rts[2]+1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[2] = rtsNew[2];
rts[3] = rtsNew[3];
}
else if (rts[2]>currentJD) // found time after current date
{
core1->setJD(rts[2]-1.); // try again for current date
core1->update(0); // force update to get new coordinates
rtsNew = getClosestRTSTime(core1,altitude);
rts[2] = rtsNew[2];
rts[3] = rtsNew[3];
}
}

double mr = rts[0];
double mt = rts[1];
double ms = rts[2];
int flag = rts[3];
if (flag==0)
{
StelUtils::getDateFromJulianDay(mt+utcShift, &year, &month, &day);
if (day != currentdate) flag = 20; // no transit
StelUtils::getDateFromJulianDay(mr+utcShift, &year, &month, &day);
if (day != currentdate) flag = 30; // no rise
StelUtils::getDateFromJulianDay(ms+utcShift, &year, &month, &day);
if (day != currentdate) flag = 40; // no set
}
core1->setJD(currentJD);
core1->setMilliSecondsOfLastJDUpdate(millis); // restore millis.
core1->update(0); // enforce update

return Vec4d(mr, mt, ms, flag);
}
7 changes: 7 additions & 0 deletions src/core/modules/Planet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ class Planet : public StelObject
//! * -1000. is used as "invalid" value. The result should then not be used.
//! @note This is based on Meeus, Astronomical Algorithms (2nd ed.), but deviates in details.
//! @note Limitation for efficiency: If this is a planet moon from another planet, we compute RTS for the parent planet instead!
virtual Vec4d getClosestRTSTime(const StelCore* core, const double altitude=0.) const;

//! Adaptation of getClosestRTSTime() to compute times of rise, transit and set for a solar system object for current location and date.
//! @note The fourth element flags particular conditions:
//! * +20 for objects with no transit time on current date.
//! * +30 for objects with no rise time on current date.
//! * +40 for objects with no set time on current date.
virtual Vec4d getRTSTime(const StelCore* core, const double altitude=0.) const Q_DECL_OVERRIDE;

void resetTextures();
Expand Down
Loading