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

214 lines
6.4 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. #ifndef ANTKEEPER_COORDINATES_ECLIPTIC_HPP
  20. #define ANTKEEPER_COORDINATES_ECLIPTIC_HPP
  21. #include "coordinates/rectangular.hpp"
  22. #include "coordinates/spherical.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. #include <cmath>
  25. namespace coordinates {
  26. namespace rectangular {
  27. /// Rectangular coordinate system with the plane of the Earth's orbit as the fundamental plane. This is a right-handed coordinate system with the x-axis pointing to the vernal equinox, the y-axis pointing east, and the z-axis is the north orbital pole.
  28. namespace ecliptic {
  29. /**
  30. * Produces a matrix which rotates rectangular coordinates from ecliptic space into equatorial space.
  31. *
  32. * @param ecl Obliquity of the ecliptic, in radians.
  33. * @return Rotation matrix.
  34. *
  35. * @see coordinates::rectangular::equatorial
  36. */
  37. template <class T>
  38. math::matrix3<T> to_equatorial(T ecl);
  39. /**
  40. * Rotates rectangular coordinates from ecliptic space into equatorial space.
  41. *
  42. * @param v Rectangular coordinates in ecliptic space.
  43. * @param ecl Obliquity of the ecliptic, in radians.
  44. * @return Rectangular coordinates in equatorial space.
  45. *
  46. * @see coordinates::rectangular::equatorial
  47. */
  48. template <class T>
  49. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl);
  50. /**
  51. * Produces a matrix which rotates rectangular coordinates from ecliptic space into local horizontal space.
  52. *
  53. * @param ecl Obliquity of the ecliptic, in radians.
  54. * @param lat Observer's latitude, in radians.
  55. * @param lst Local sidereal time, in radians.
  56. * @return Rotation matrix.
  57. *
  58. * @see coordinates::rectangular::horizontal
  59. */
  60. template <class T>
  61. math::matrix3<T> to_horizontal(T ecl, T lat, T lst);
  62. /**
  63. * Rotates rectangular coordinates from ecliptic space into local horizontal space.
  64. *
  65. * @param v Rectangular coordinates in ecliptic space.
  66. * @param ecl Obliquity of the ecliptic, in radians.
  67. * @param lat Observer's latitude, in radians.
  68. * @param lst Local sidereal time, in radians.
  69. * @return Rectangular coordinates in local horizontal space.
  70. *
  71. * @see coordinates::rectangular::horizontal
  72. */
  73. template <class T>
  74. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst);
  75. } // namespace ecliptic
  76. } // namespace rectangular
  77. namespace spherical {
  78. /// Spherical ecliptic coordinate system.
  79. namespace ecliptic {
  80. /**
  81. * Rotates spherical coordinates from ecliptic space into equatorial space.
  82. *
  83. * @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians).
  84. * @param ecl Obliquity of the ecliptic, in radians.
  85. * @return Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians).
  86. *
  87. * @see coordinates::spherical::equatorial
  88. */
  89. template <class T>
  90. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl);
  91. /**
  92. * Rotates spherical coordinates from ecliptic space into local horizontal space.
  93. *
  94. * @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians).
  95. * @param ecl Obliquity of the ecliptic, in radians.
  96. * @param lat Observer's latitude, in radians.
  97. * @param lst Local sidereal time, in radians.
  98. * @return Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians).
  99. *
  100. * @see coordinates::spherical::horizontal
  101. */
  102. template <class T>
  103. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst);
  104. } // namespace ecliptic
  105. } // namespace spherical
  106. namespace rectangular {
  107. namespace ecliptic {
  108. template <class T>
  109. math::matrix3<T> to_equatorial(T ecl)
  110. {
  111. const T c_ecl = std::cos(ecl);
  112. const T s_ecl = std::sin(ecl);
  113. return math::matrix3<T>
  114. {
  115. T(1.0), T(0.0), T(0.0),
  116. T(0.0), c_ecl, s_ecl,
  117. T(0.0), -s_ecl, c_ecl
  118. };
  119. }
  120. template <class T>
  121. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl)
  122. {
  123. return to_equatorial<T>(ecl) * v;
  124. }
  125. template <class T>
  126. math::matrix3<T> to_horizontal(T ecl, T lat, T lst)
  127. {
  128. const T c_ecl = std::cos(ecl);
  129. const T s_ecl = std::sin(ecl);
  130. const T c_lat = std::cos(lat);
  131. const T s_lat = std::sin(lat);
  132. const T c_lst = std::cos(lst);
  133. const T s_lst = std::sin(lst);
  134. return math::matrix3<T>
  135. {
  136. s_lat * c_lst, s_lst, c_lat * c_lst,
  137. s_lat * s_lst * c_ecl - c_lat * s_ecl, -c_lst * c_ecl, c_lat * s_lst * c_ecl + s_lat * s_ecl,
  138. s_lat * s_lst * -s_ecl - c_lat * c_ecl, c_lst * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl
  139. };
  140. }
  141. template <class T>
  142. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst)
  143. {
  144. return to_horizontal<T>(ecl, lat, lst) * v;
  145. }
  146. } // namespace ecliptic
  147. } // namespace rectangular
  148. namespace spherical {
  149. namespace ecliptic {
  150. template <class T>
  151. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl)
  152. {
  153. return coordinates::rectangular::to_spherical<T>
  154. (
  155. coordinates::rectangular::ecliptic::to_equatorial<T>
  156. (
  157. coordinates::spherical::to_rectangular<T>(v),
  158. ecl
  159. )
  160. );
  161. }
  162. template <class T>
  163. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst)
  164. {
  165. return coordinates::rectangular::to_spherical<T>
  166. (
  167. coordinates::rectangular::ecliptic::to_horizontal<T>
  168. (
  169. coordinates::spherical::to_rectangular<T>(v),
  170. ecl,
  171. lat,
  172. lst
  173. )
  174. );
  175. }
  176. } // namespace ecliptic
  177. } // namespace spherical
  178. } // namespace coordinates
  179. #endif // ANTKEEPER_COORDINATES_ECLIPTIC_HPP