5#include <janus/janus.hpp>
29template <
typename Scalar>
34 const Scalar x = r_ecef(0);
35 const Scalar y = r_ecef(1);
36 const Scalar z = r_ecef(2);
38 const Scalar r2 = x * x + y * y + z * z;
39 const Scalar r = janus::sqrt(r2);
40 const Scalar r3 = r2 * r;
43 const Scalar z2_over_r2 = z * z / r2;
44 const Scalar R_eq_over_r_sq = (R_eq * R_eq) / r2;
45 const Scalar J2_factor = 1.5 * J2_coeff * R_eq_over_r_sq;
48 const Scalar pm_coeff = -mu / r3;
51 const Scalar xy_factor = 1.0 - J2_factor * (5.0 * z2_over_r2 - 1.0);
52 const Scalar z_factor = 1.0 - J2_factor * (5.0 * z2_over_r2 - 3.0);
55 accel(0) = pm_coeff * x * xy_factor;
56 accel(1) = pm_coeff * y * xy_factor;
57 accel(2) = pm_coeff * z * z_factor;
76template <
typename Scalar>
80 const Scalar x = r_ecef(0);
81 const Scalar y = r_ecef(1);
82 const Scalar z = r_ecef(2);
84 const Scalar r2 = x * x + y * y + z * z;
85 const Scalar r = janus::sqrt(r2);
88 const Scalar sin_phi = z / r;
89 const Scalar sin_phi_sq = sin_phi * sin_phi;
92 const Scalar P2 = (3.0 * sin_phi_sq - 1.0) / 2.0;
95 const Scalar R_eq_over_r_sq = (R_eq * R_eq) / r2;
97 return -mu / r * (1.0 - J2_coeff * R_eq_over_r_sq * P2);
constexpr double R_eq
Equatorial radius [m] (WGS84).
Definition Constants.hpp:16
constexpr double J2
J2 zonal harmonic coefficient.
Definition Constants.hpp:28
constexpr double mu
Gravitational parameter (GM) [m^3/s^2].
Definition Constants.hpp:13
Vec3< Scalar > acceleration(const Vec3< Scalar > &r_ecef, double mu=constants::earth::mu, double J2_coeff=constants::earth::J2, double R_eq=constants::earth::R_eq)
J2 gravitational acceleration (oblate Earth).
Definition J2.hpp:30
Scalar potential(const Vec3< Scalar > &r_ecef, double mu=constants::earth::mu, double J2_coeff=constants::earth::J2, double R_eq=constants::earth::R_eq)
J2 gravitational potential.
Definition J2.hpp:77