diff --git a/cxx/mcc_mount_pz.h b/cxx/mcc_mount_pz.h index 4fc29fa..8a1dd55 100644 --- a/cxx/mcc_mount_pz.h +++ b/cxx/mcc_mount_pz.h @@ -16,7 +16,7 @@ namespace mcc { -static constexpr double mcc_UT1_to_sideral_ratio = 1.002737909350795; // UT1/sideral +static constexpr double mcc_sideral_to_UT1_ratio = 1.002737909350795; // sideral/UT1 /* SOME SIMPLE PROHIBITED ZONE IMPLEMENTATIONS */ @@ -86,7 +86,13 @@ public: return infDuration; } - return compute(telemetry_data); + if constexpr (KIND == + MccAltLimitKind::MIN_ALT_LIMIT) { // the closest time point is one after upper culmination + return compute(telemetry_data, false); + } else if constexpr (KIND == MccAltLimitKind::MAX_ALT_LIMIT) { // the closest time point is one before upper + // culmination + return compute(telemetry_data, true); + } } // returns a time to exit from the zone @@ -100,7 +106,13 @@ public: return zeroDuration; } - return compute(telemetry_data); + if constexpr (KIND == + MccAltLimitKind::MIN_ALT_LIMIT) { // the closest time point is one before upper culmination + return compute(telemetry_data, true); + } else if constexpr (KIND == MccAltLimitKind::MAX_ALT_LIMIT) { // the closest time point is one after upper + // culmination + return compute(telemetry_data, false); + } } template XT, std::derived_from YT> @@ -174,7 +186,7 @@ private: return true; } - pz_duration_t compute(traits::mcc_mount_telemetry_data_c auto const& telemetry_data) + pz_duration_t compute(traits::mcc_mount_telemetry_data_c auto const& telemetry_data, bool before_upper_culm) { double cos_ha = (std::sin(_altLimit) - std::sin(telemetry_data.mntDEC) * std::sin(_latitude)) / std::cos(telemetry_data.mntDEC) / std::cos(_latitude); @@ -183,12 +195,31 @@ private: return infDuration; } - MccAngle time_ang = std::acos(cos_ha) - telemetry_data.mntHA; // in sideral time scale - if (time_ang < 0.0) { // next day + double ha; + if (before_upper_culm) { + ha = -std::acos(cos_ha); // HA before upper culmination + } else { + ha = std::acos(cos_ha); // HA after upper culmination!! + } + + // if constexpr (KIND == MccAltLimitKind::MIN_ALT_LIMIT) { // the closest time moment after upper + // culmination!!! + // ha = std::acos(cos_ha); // HA after upper culmination!! + // } else if constexpr (KIND == + // MccAltLimitKind::MAX_ALT_LIMIT) { // the closest time moment before upper + // culmination!!! + // ha = -std::acos(cos_ha); // HA before upper culmination + // } else { + // static_assert(false, "UNKNOWN ALTITUDE LIMIT TYPE!"); + // } + + MccAngle time_ang = ha - telemetry_data.mntHA; // in sideral time scale + + if (time_ang < 0.0) { // next day time_ang += pi2; } - time_ang *= mcc_UT1_to_sideral_ratio; + time_ang /= mcc_sideral_to_UT1_ratio; // to UT1 time scale return pz_duration_t{time_ang.seconds()}; } diff --git a/cxx/tests/astrom_test.cpp b/cxx/tests/astrom_test.cpp index 67e9984..0a93c88 100644 --- a/cxx/tests/astrom_test.cpp +++ b/cxx/tests/astrom_test.cpp @@ -219,6 +219,14 @@ int main(int argc, char* argv[]) std::cout << "(MINALT) time to zone: " << std::chrono::hh_mm_ss(tm) << " (" << now1 << ")\n"; } + tm = minalt_pz.timeFrom(tdata); + if (std::isinf(tm.count())) { + std::cout << "(MINALT) time from zone: the object never reaches the zone!\n"; + } else { + auto now1 = now + std::chrono::duration_cast(tm); + std::cout << "(MINALT) time from zone: " << std::chrono::hh_mm_ss(tm) << " (" << now1 << ")\n"; + } + std::cout << "\n"; ra1 = "17:00:00"_hms; @@ -235,13 +243,27 @@ int main(int argc, char* argv[]) tdata = {ra_o, dec_o, ha1, az1, alt1, 0.0, 0.0}; + jd.mjd += 1.0; + res = erfa.icrs2obs(ra1, dec1, jd, ra_o, dec_o, ha1, az1, alt1, eor); + std::cout << "RA_app (+24h) = " << ra_o.sexagesimal(true) << "\n"; + tm = maxalt_pz.timeTo(tdata); if (std::isinf(tm.count())) { std::cout << "(MAXALT) time to zone: the object never reaches the zone!\n"; } else { + // auto ns = std::chrono::duration_cast(tm); auto now1 = now + std::chrono::duration_cast(tm); + // auto now1 = now + ns; std::cout << "(MAXALT) time to zone: " << std::chrono::hh_mm_ss(tm) << " (" << now1 << ")\n"; } + tm = maxalt_pz.timeFrom(tdata); + if (std::isinf(tm.count())) { + std::cout << "(MAXALT) time from zone: the object never reaches the zone!\n"; + } else { + auto now1 = now + std::chrono::duration_cast(tm); + std::cout << "(MAXALT) time from zone: " << std::chrono::hh_mm_ss(tm) << " (" << now1 << ")\n"; + } + return ecode; }