💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

  1. /*
  2. * Copyright (C) 2020 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "celestial-time.hpp"
  20. #include "math/angles.hpp"
  21. #include <cmath>
  22. namespace ast
  23. {
  24. double ut_to_jd(int year, int month, int day, int hour, int minute, double second)
  25. {
  26. if (month < 3)
  27. {
  28. month += 12;
  29. year -= 1;
  30. }
  31. const signed long Y = year;
  32. const signed long M = month;
  33. const signed long D = day;
  34. const signed long JDN = (1461*(Y+4800+(M-14)/12))/4+(367*(M-2-12*((M-14)/12)))/12-(3*((Y+4900+(M-14)/12)/100))/4+D-32075;
  35. const double h = static_cast<double>(hour - 12) / 24.0;
  36. const double m = static_cast<double>(minute) / 1440.0;
  37. const double s = second / 86400.0;
  38. return static_cast<double>(JDN) + h + m + s;
  39. }
  40. double jd_to_gmst(double jd)
  41. {
  42. return math::wrap_radians<double>(4.894961212 + 6.300388098 * (jd - 2451545.0));
  43. }
  44. double jd_to_lmst(double jd, double longitude)
  45. {
  46. return gmst_to_lmst(jd_to_gmst(jd), longitude);
  47. }
  48. double gmst_to_lmst(double gmst, double longitude)
  49. {
  50. return gmst + longitude;
  51. }
  52. } // namespace ast