20 #ifndef ANTKEEPER_PHYSICS_ORBIT_ANOMALY_HPP
21 #define ANTKEEPER_PHYSICS_ORBIT_ANOMALY_HPP
98 T
mean_to_true(T ec, T ma, std::size_t iterations, T tolerance);
105 return std::tan(ta * T(0.5));
109 return std::acosh((ec + std::cos(ta)) / (T(1) + ec * std::cos(ta))) * ((ta < T(0)) ? T(-1) : T(1));
112 return std::atan2(
std::sqrt(T(1) - ec * ec) * std::sin(ta), std::cos(ta) + ec);
126 return std::atan(ea) * T(2);
130 return std::atan(
std::sqrt((ec + T(1)) / (ec - T(1))) * std::tanh(ea * T(0.5))) * T(2);
133 return std::atan2(
sqrt(T(1) - ec * ec) * std::sin(ea), std::cos(ea) - ec);
141 return (ea * ea * ea) / T(6) + ea * T(0.5);
145 return ec * std::sinh(ea) - ea;
148 return ea - ec * std::sin(ea);
155 ma = std::remainder(ma, math::two_pi<T>);
158 const T t33 = std::cos(ma);
159 const T t34 = ec * ec;
160 const T t35 = t34 * ec;
161 T ea0 = ma + (T(-0.5) * t35 + ec + (t34 + T(1.5) * t33 * t35) * t33) * std::sin(ma);
164 for (std::size_t i = 0; i < iterations; ++i)
167 const T t1 = std::cos(ea0);
168 const T t2 = T(-1) + ec * t1;
169 const T t3 = std::sin(ea0);
170 const T t4 = ec * t3;
171 const T t5 = -ea0 + t4 + ma;
172 const T t6 = t5 / (T(0.5) * t5 * t4 / t2 + t2);
173 const T ea1 = ea0 - (t5 / ((T(0.5) * t3 - (T(1) / T(6)) * t1 * t6) * ec * t6 + t2));
176 const T error =
std::abs(ea1 - ea0);
182 if (error < tolerance)
constexpr vector< T, N > abs(const vector< T, N > &x)
Returns the absolute values of each element.
vector< T, N > sqrt(const vector< T, N > &x)
Takes the square root of each element.
T mean_to_true(T ec, T ma, std::size_t iterations, T tolerance)
Iteratively derives the true anomaly given eccentricity and mean anomaly.
T mean_to_eccentric(T ec, T ma, std::size_t iterations, T tolerance)
Iteratively derives the eccentric anomaly given eccentricity and mean anomaly.
T eccentric_to_mean(T ec, T ea)
Derives the mean anomaly given eccentricity and eccentric anomaly.
T true_to_mean(T ec, T ta)
Derives the mean anomaly given eccentricity and true anomaly.
T eccentric_to_true(T ec, T ea)
Derives the true anomaly given eccentricity and eccentric anomaly.
T true_to_eccentric(T ec, T ta)
Derives the eccentric anomaly given eccentricity and true anomaly.