💿🐜 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.

138 lines
3.6 KiB

  1. /*
  2. * Copyright (C) 2021 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 "coordinates.hpp"
  20. #include <cmath>
  21. namespace astro
  22. {
  23. double3 rectangular_to_spherical(const double3& rectangular)
  24. {
  25. const double xx_yy = rectangular.x * rectangular.x + rectangular.y * rectangular.y;
  26. return double3
  27. {
  28. std::sqrt(xx_yy + rectangular.z * rectangular.z),
  29. std::atan2(rectangular.z, std::sqrt(xx_yy)),
  30. std::atan2(rectangular.y, rectangular.x)
  31. };
  32. }
  33. double3 spherical_to_rectangular(const double3& spherical)
  34. {
  35. return double3
  36. {
  37. spherical[0] * std::cos(spherical[1]) * std::cos(spherical[2]),
  38. spherical[0] * std::cos(spherical[1]) * std::sin(spherical[2]),
  39. spherical[0] * std::sin(spherical[1]),
  40. };
  41. }
  42. double3x3 ecliptic_to_equatorial(double ecl)
  43. {
  44. const double c_ecl = std::cos(ecl);
  45. const double s_ecl = std::sin(ecl);
  46. return double3x3
  47. {
  48. 1.0, 0.0, 0.0,
  49. 0.0, c_ecl, s_ecl,
  50. 0.0, -s_ecl, c_ecl
  51. };
  52. }
  53. double3x3 ecliptic_to_horizontal(double ecl, double lat, double lst)
  54. {
  55. const double c_ecl = std::cos(ecl);
  56. const double s_ecl = std::sin(ecl);
  57. const double c_lat = std::cos(lat);
  58. const double s_lat = std::sin(lat);
  59. const double c_lst = std::cos(lst);
  60. const double s_lst = std::sin(lst);
  61. return double3x3
  62. {
  63. s_lat * c_lst, s_lst, c_lat * c_lst,
  64. s_lat * s_lst * c_ecl - c_lat * s_ecl, -c_lst * c_ecl, c_lat * s_lst * c_ecl + s_lat * s_ecl,
  65. s_lat * s_lst * -s_ecl - c_lat * c_ecl, c_lst * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl
  66. };
  67. }
  68. double3x3 equatorial_to_ecliptic(double ecl)
  69. {
  70. const double c_ecl = std::cos(ecl);
  71. const double s_ecl = std::sin(ecl);
  72. return double3x3
  73. {
  74. 1.0, 0.0, 0.0,
  75. 0.0, c_ecl, -s_ecl,
  76. 0.0, s_ecl, c_ecl
  77. };
  78. }
  79. double3x3 equatorial_to_horizontal(double lat, double lst)
  80. {
  81. const double c_lat = std::cos(lat);
  82. const double s_lat = std::sin(lat);
  83. const double c_lst = std::cos(lst);
  84. const double s_lst = std::sin(lst);
  85. return double3x3
  86. {
  87. s_lat * c_lst, s_lst, c_lat * c_lst,
  88. s_lat * s_lst, -c_lst, c_lat * s_lst,
  89. -c_lat, 0.0, s_lat
  90. };
  91. }
  92. double3x3 horizontal_to_equatorial(double lat, double lst)
  93. {
  94. const double c_lat = std::cos(lat);
  95. const double s_lat = std::sin(lat);
  96. const double c_lst = std::cos(lst);
  97. const double s_lst = std::sin(lst);
  98. return double3x3
  99. {
  100. c_lst * s_lat, s_lst * s_lat, -c_lat,
  101. s_lst, c_lst, 0.0,
  102. c_lst * c_lat, s_lst * c_lat, s_lat
  103. };
  104. }
  105. double3x3 horizontal_to_ecliptic(double ecl, double lat, double lst)
  106. {
  107. const double c_ecl = std::cos(ecl);
  108. const double s_ecl = std::sin(ecl);
  109. const double c_lat = std::cos(lat);
  110. const double s_lat = std::sin(lat);
  111. const double c_lst = std::cos(lst);
  112. const double s_lst = std::sin(lst);
  113. return double3x3
  114. {
  115. s_lat * c_lst, s_lat * s_lst * c_ecl - c_lat * s_ecl, s_lat * s_lst * -s_ecl - c_lat * c_ecl,
  116. s_lst, -c_lst * c_ecl, c_lst * s_ecl,
  117. c_lat * c_lst, c_lat * s_lst * c_ecl + s_lat * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl
  118. };
  119. }
  120. } // namespace astro