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

95 lines
2.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_PHYSICS_ORBIT_ELEMENTS_HPP
  20. #define ANTKEEPER_PHYSICS_ORBIT_ELEMENTS_HPP
  21. #include "utility/fundamental-types.hpp"
  22. #include "physics/orbit/state.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 e;
  38. /// Semimajor axis (a).
  39. scalar_type a;
  40. /// Inclination (i), in radians.
  41. scalar_type i;
  42. /// Right ascension of the ascending node (OMEGA), in radians.
  43. scalar_type raan;
  44. /// Argument of periapsis (omega), in radians.
  45. scalar_type w;
  46. /// True anomaly (nu) at epoch, in radians.
  47. scalar_type ta;
  48. };
  49. /**
  50. * Derives the longitude of the periapsis (pomega) of an orbit, given the argument of periapsis (omega) and longitude of the ascending node (OMEGA).
  51. *
  52. * @param w Argument of periapsis (omega), in radians.
  53. * @param raan Right ascension of the ascending node (OMEGA), in radians.
  54. * @return Longitude of the periapsis (pomega), in radians.
  55. */
  56. template <class T>
  57. T derive_longitude_periapsis(T w, T raan);
  58. /**
  59. * Derives the semiminor axis (b) of an orbit, given the semimajor axis (a) and eccentricity (e).
  60. *
  61. * @param a Semimajor axis (a).
  62. * @param e Eccentricity (e).
  63. * @return Semiminor axis (b).
  64. */
  65. template <class T>
  66. T derive_semiminor_axis(T a, T e);
  67. template <class T>
  68. T derive_longitude_periapsis(T w, T raan)
  69. {
  70. return w + raan;
  71. }
  72. template <class T>
  73. T derive_semiminor_axis(T a, T e)
  74. {
  75. return a * std::sqrt(T(1) - e * e);
  76. }
  77. } // namespace orbit
  78. } // namespace physics
  79. #endif // ANTKEEPER_PHYSICS_ORBIT_ELEMENTS_HPP