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

174 lines
4.1 KiB

  1. /*
  2. * Copyright (C) 2023 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_PHYSICS_ORBIT_ELEMENTS_HPP
  20. #define ANTKEEPER_PHYSICS_ORBIT_ELEMENTS_HPP
  21. #include "utility/fundamental-types.hpp"
  22. #include "math/numbers.hpp"
  23. #include <cmath>
  24. namespace physics {
  25. namespace orbit {
  26. /**
  27. * Set of six Keplerian elements required to uniquely identify an orbit.
  28. *
  29. * @tparam T Scalar type.
  30. */
  31. template <class T>
  32. struct elements
  33. {
  34. /// Scalar type.
  35. typedef T scalar_type;
  36. /// Eccentricity (e).
  37. scalar_type ec;
  38. /// Semimajor axis (a).
  39. scalar_type a;
  40. /// Inclination (i), in radians.
  41. scalar_type in;
  42. /// Right ascension of the ascending node (OMEGA), in radians.
  43. scalar_type om;
  44. /// Argument of periapsis (omega), in radians.
  45. scalar_type w;
  46. /// Mean anomaly (M) at epoch, in radians.
  47. scalar_type ma;
  48. };
  49. /**
  50. * Calculates the period of an elliptical orbit according to Kepler's third law.
  51. *
  52. * @param a Semimajor axis (a).
  53. * @param gm Standard gravitational parameter (GM).
  54. * @return Orbital period (T).
  55. */
  56. template <class T>
  57. T period(T a, T gm);
  58. /**
  59. * Calculates the mean motion (n) of an orbit.
  60. *
  61. * @param a Semimajor axis (a).
  62. * @param gm Standard gravitational parameter (GM).
  63. * @return Mean motion (n), in radians per unit time.
  64. */
  65. template <class T>
  66. T mean_motion(T a, T gm);
  67. /**
  68. * Calculates the mean motion (n) of an orbit.
  69. *
  70. * @param t Orbital period (T).
  71. * @return Mean motion (n), in radians per unit time.
  72. */
  73. template <class T>
  74. T mean_motion(T t);
  75. /**
  76. * Derives the argument of the periapsis (omega) of an orbit, given the longitude of periapsis (pomega) and longitude of the ascending node (OMEGA).
  77. *
  78. * @param lp Longitude of the periapsis (pomega), in radians.
  79. * @param om Right ascension of the ascending node (OMEGA), in radians.
  80. * @return Argument of the periapsis (omega), in radians.
  81. */
  82. template <class T>
  83. T argument_periapsis(T om, T lp);
  84. /**
  85. * Derives the longitude of the periapsis (pomega) of an orbit, given the argument of periapsis (omega) and longitude of the ascending node (OMEGA).
  86. *
  87. * @param w Argument of the periapsis (omega), in radians.
  88. * @param om Right ascension of the ascending node (OMEGA), in radians.
  89. * @return Longitude of the periapsis (pomega), in radians.
  90. */
  91. template <class T>
  92. T longitude_periapsis(T om, T w);
  93. /**
  94. * Derives the semiminor axis (b) of an orbit, given the semimajor axis (a) and eccentricity (e).
  95. *
  96. * @param a Semimajor axis (a).
  97. * @param ec Eccentricity (e).
  98. * @return Semiminor axis (b).
  99. */
  100. template <class T>
  101. T semiminor_axis(T a, T ec);
  102. /**
  103. * Derives the semi-latus rectum (l) of an orbit, given the semimajor axis (a) and eccentricity (e).
  104. *
  105. * @param a Semimajor axis (a).
  106. * @param ec Eccentricity (e).
  107. * @return Semi-latus rectum (l).
  108. */
  109. template <class T>
  110. T semilatus_rectum(T a, T ec);
  111. template <class T>
  112. T period(T a, T gm)
  113. {
  114. return math::two_pi<T> * std::sqrt((a * a * a) / gm);
  115. }
  116. template <class T>
  117. T mean_motion(T a, T gm)
  118. {
  119. return std::sqrt((a * a * a) / gm);
  120. }
  121. template <class T>
  122. T mean_motion(T t)
  123. {
  124. return math::two_pi<T> / t;
  125. }
  126. template <class T>
  127. T argument_periapsis(T om, T lp)
  128. {
  129. return lp - om;
  130. }
  131. template <class T>
  132. T longitude_periapsis(T om, T w)
  133. {
  134. return w + om;
  135. }
  136. template <class T>
  137. T semiminor_axis(T a, T ec)
  138. {
  139. return a * std::sqrt(T(1) - ec * ec);
  140. }
  141. template <class T>
  142. T semilatus_rectum(T a, T ec)
  143. {
  144. return a * (T(1) - ec * ec);
  145. }
  146. } // namespace orbit
  147. } // namespace physics
  148. #endif // ANTKEEPER_PHYSICS_ORBIT_ELEMENTS_HPP