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

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