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

220 lines
6.7 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::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. * @note If more than one point is being rotated, it is recommended to use the rotation matrix directly.
  47. *
  48. * @see coordinates::ecliptic::rectangular::to_equatorial(T)
  49. * @see coordinates::equatorial
  50. */
  51. template <class T>
  52. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl);
  53. /**
  54. * Produces a matrix which rotates rectangular coordinates from ecliptic space into local horizontal space.
  55. *
  56. * @param ecl Obliquity of the ecliptic, in radians.
  57. * @param lat Observer's latitude, in radians.
  58. * @param lst Local sidereal time, in radians.
  59. * @return Rotation matrix.
  60. *
  61. * @see coordinates::horizontal
  62. */
  63. template <class T>
  64. math::matrix3<T> to_horizontal(T ecl, T lat, T lst);
  65. /**
  66. * Rotates rectangular coordinates from ecliptic space into local horizontal space.
  67. *
  68. * @param v Rectangular coordinates in ecliptic space.
  69. * @param ecl Obliquity of the ecliptic, in radians.
  70. * @param lat Observer's latitude, in radians.
  71. * @param lst Local sidereal time, in radians.
  72. * @return Rectangular coordinates in local horizontal space.
  73. *
  74. * @note If more than one point is being rotated, it is recommended to use the rotation matrix directly.
  75. *
  76. * @see coordinates::ecliptic::rectangular::to_horizontal(T, T, T)
  77. * @see coordinates::horizontal
  78. */
  79. template <class T>
  80. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst);
  81. } // namespace ecliptic
  82. } // namespace rectangular
  83. namespace spherical {
  84. /// Spherical equatorial coordinate system.
  85. namespace ecliptic {
  86. /**
  87. * Rotates spherical coordinates from ecliptic space into equatorial space.
  88. *
  89. * @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians).
  90. * @param ecl Obliquity of the ecliptic, in radians.
  91. * @return Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians).
  92. *
  93. * @see coordinates::equatorial
  94. */
  95. template <class T>
  96. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl);
  97. /**
  98. * Rotates spherical coordinates from ecliptic space into local horizontal space.
  99. *
  100. * @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians).
  101. * @param ecl Obliquity of the ecliptic, in radians.
  102. * @param lat Observer's latitude, in radians.
  103. * @param lst Local sidereal time, in radians.
  104. * @return Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians).
  105. *
  106. * @see coordinates::horizontal
  107. */
  108. template <class T>
  109. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst);
  110. } // namespace ecliptic
  111. } // namespace spherical
  112. namespace rectangular {
  113. namespace ecliptic {
  114. template <class T>
  115. math::matrix3<T> to_equatorial(T ecl)
  116. {
  117. const T c_ecl = std::cos(ecl);
  118. const T s_ecl = std::sin(ecl);
  119. return math::matrix3<T>
  120. {
  121. T(1.0), T(0.0), T(0.0),
  122. T(0.0), c_ecl, s_ecl,
  123. T(0.0), -s_ecl, c_ecl
  124. };
  125. }
  126. template <class T>
  127. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl)
  128. {
  129. return to_equatorial<T>(ecl) * v;
  130. }
  131. template <class T>
  132. math::matrix3<T> to_horizontal(T ecl, T lat, T lst)
  133. {
  134. const T c_ecl = std::cos(ecl);
  135. const T s_ecl = std::sin(ecl);
  136. const T c_lat = std::cos(lat);
  137. const T s_lat = std::sin(lat);
  138. const T c_lst = std::cos(lst);
  139. const T s_lst = std::sin(lst);
  140. return math::matrix3<T>
  141. {
  142. s_lat * c_lst, s_lst, c_lat * c_lst,
  143. s_lat * s_lst * c_ecl - c_lat * s_ecl, -c_lst * c_ecl, c_lat * s_lst * c_ecl + s_lat * s_ecl,
  144. s_lat * s_lst * -s_ecl - c_lat * c_ecl, c_lst * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl
  145. };
  146. }
  147. template <class T>
  148. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst)
  149. {
  150. return to_horizontal<T>(ecl, lat, lst) * v;
  151. }
  152. } // namespace ecliptic
  153. } // namespace rectangular
  154. namespace spherical {
  155. namespace ecliptic {
  156. template <class T>
  157. math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl)
  158. {
  159. return coordinates::rectangular::to_spherical<T>
  160. (
  161. coordinates::rectangular::ecliptic::to_equatorial<T>
  162. (
  163. coordinates::spherical::to_rectangular<T>(v),
  164. ecl
  165. )
  166. );
  167. }
  168. template <class T>
  169. math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst)
  170. {
  171. return coordinates::rectangular::to_spherical<T>
  172. (
  173. coordinates::rectangular::ecliptic::to_horizontal<T>
  174. (
  175. coordinates::spherical::to_rectangular<T>(v),
  176. ecl,
  177. lat,
  178. lst
  179. )
  180. );
  181. }
  182. } // namespace ecliptic
  183. } // namespace spherical
  184. } // namespace coordinates
  185. #endif // ANTKEEPER_COORDINATES_ECLIPTIC_HPP