6#include <janus/janus.hpp>
24template <
typename Scalar>
30 if constexpr (std::is_same_v<Scalar, double>) {
32 for (
int iter = 0; iter < max_iter; ++iter) {
33 double f = E - e * std::sin(E) - M;
34 double f_prime = 1.0 - e * std::cos(E);
35 double dE = f / f_prime;
37 if (std::abs(dE) < tol)
42 for (
int iter = 0; iter < 10; ++iter) {
43 Scalar f = E - e * janus::sin(E) - M;
44 Scalar f_prime = 1.0 - e * janus::cos(E);
60template <
typename Scalar>
62 const Scalar cos_E = janus::cos(E);
63 const Scalar sin_E = janus::sin(E);
64 const Scalar sqrt_term = janus::sqrt(1.0 - e * e);
66 return janus::atan2(sqrt_term * sin_E, cos_E - e);
77template <
typename Scalar>
79 const Scalar cos_nu = janus::cos(nu);
80 const Scalar sin_nu = janus::sin(nu);
81 const Scalar sqrt_term = janus::sqrt(1.0 - e * e);
83 return janus::atan2(sqrt_term * sin_nu, e + cos_nu);
96template <
typename Scalar>
98 return E - e * janus::sin(E);
109template <
typename Scalar>
123template <
typename Scalar>
Definition AnomalyConversions.hpp:9
Scalar mean_to_true(const Scalar &M, const Scalar &e)
Convert mean anomaly to true anomaly.
Definition AnomalyConversions.hpp:124
Scalar mean_to_eccentric(const Scalar &M, const Scalar &e, double tol=1e-12, int max_iter=50)
Solve Kepler's equation: M = E - e*sin(E).
Definition AnomalyConversions.hpp:25
Scalar true_to_mean(const Scalar &nu, const Scalar &e)
Convert true anomaly to mean anomaly.
Definition AnomalyConversions.hpp:110
Scalar eccentric_to_mean(const Scalar &E, const Scalar &e)
Convert eccentric anomaly to mean anomaly.
Definition AnomalyConversions.hpp:97
Scalar true_to_eccentric(const Scalar &nu, const Scalar &e)
Convert true anomaly to eccentric anomaly.
Definition AnomalyConversions.hpp:78
Scalar eccentric_to_true(const Scalar &E, const Scalar &e)
Convert eccentric anomaly to true anomaly.
Definition AnomalyConversions.hpp:61