Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
J2J4.hpp
Go to the documentation of this file.
1// Vulcan J2-J4 Gravity Model
2// Includes J2, J3, and J4 zonal harmonic perturbations
3#pragma once
4
5#include <janus/janus.hpp>
8
10
28template <typename Scalar>
29Vec3<Scalar> acceleration(const Vec3<Scalar> &r_ecef,
30 double mu = constants::earth::mu,
31 double J2_coeff = constants::earth::J2,
32 double J3_coeff = constants::earth::J3,
33 double J4_coeff = constants::earth::J4,
34 double R_eq = constants::earth::R_eq) {
35 const Scalar x = r_ecef(0);
36 const Scalar y = r_ecef(1);
37 const Scalar z = r_ecef(2);
38
39 const Scalar r2 = x * x + y * y + z * z;
40 const Scalar r = janus::sqrt(r2);
41 const Scalar r3 = r2 * r;
42
43 // Normalized z coordinate
44 const Scalar z_r = z / r;
45 const Scalar z_r2 = z_r * z_r;
46 const Scalar z_r3 = z_r2 * z_r;
47 const Scalar z_r4 = z_r2 * z_r2;
48
49 // R_eq / r ratios
50 const Scalar Re_r = R_eq / r;
51 const Scalar Re_r2 = Re_r * Re_r;
52 const Scalar Re_r3 = Re_r2 * Re_r;
53 const Scalar Re_r4 = Re_r2 * Re_r2;
54
55 // Base acceleration magnitude
56 const Scalar base = -mu / r3;
57
58 // ============================================
59 // J2 Terms
60 // ============================================
61 const Scalar J2_xy = -1.5 * J2_coeff * Re_r2 * (5.0 * z_r2 - 1.0);
62 const Scalar J2_z = -1.5 * J2_coeff * Re_r2 * (5.0 * z_r2 - 3.0);
63
64 // ============================================
65 // J3 Terms (odd harmonic - asymmetric about equator)
66 // Simplified form valid everywhere
67 // ============================================
68 const Scalar J3_xy = 2.5 * J3_coeff * Re_r3 * z_r * (7.0 * z_r2 - 3.0);
69 const Scalar J3_z = 2.5 * J3_coeff * Re_r3 * (7.0 * z_r3 - 3.0 * z_r);
70
71 // ============================================
72 // J4 Terms
73 // ============================================
74 const Scalar J4_xy =
75 (15.0 / 8.0) * J4_coeff * Re_r4 * (1.0 - 14.0 * z_r2 + 21.0 * z_r4);
76 const Scalar J4_z = (15.0 / 8.0) * J4_coeff * Re_r4 *
77 (5.0 - 70.0 / 3.0 * z_r2 + 21.0 * z_r4);
78
79 // ============================================
80 // Combined acceleration
81 // ============================================
82 const Scalar factor_xy = 1.0 + J2_xy + J3_xy + J4_xy;
83 const Scalar factor_z = 1.0 + J2_z + J3_z + J4_z;
84
85 Vec3<Scalar> accel;
86 accel(0) = base * x * factor_xy;
87 accel(1) = base * y * factor_xy;
88 accel(2) = base * z * factor_z;
89
90 return accel;
91}
92
107template <typename Scalar>
108Scalar potential(const Vec3<Scalar> &r_ecef, double mu = constants::earth::mu,
109 double J2_coeff = constants::earth::J2,
110 double J3_coeff = constants::earth::J3,
111 double J4_coeff = constants::earth::J4,
112 double R_eq = constants::earth::R_eq) {
113 const Scalar x = r_ecef(0);
114 const Scalar y = r_ecef(1);
115 const Scalar z = r_ecef(2);
116
117 const Scalar r2 = x * x + y * y + z * z;
118 const Scalar r = janus::sqrt(r2);
119
120 // sin(φ) = z/r
121 const Scalar sin_phi = z / r;
122 const Scalar sin_phi2 = sin_phi * sin_phi;
123 const Scalar sin_phi3 = sin_phi2 * sin_phi;
124 const Scalar sin_phi4 = sin_phi2 * sin_phi2;
125
126 // R_eq / r ratios
127 const Scalar Re_r = R_eq / r;
128 const Scalar Re_r2 = Re_r * Re_r;
129 const Scalar Re_r3 = Re_r2 * Re_r;
130 const Scalar Re_r4 = Re_r2 * Re_r2;
131
132 // Legendre polynomials P_n(sin φ)
133 const Scalar P2 = (3.0 * sin_phi2 - 1.0) / 2.0;
134 const Scalar P3 = (5.0 * sin_phi3 - 3.0 * sin_phi) / 2.0;
135 const Scalar P4 = (35.0 * sin_phi4 - 30.0 * sin_phi2 + 3.0) / 8.0;
136
137 // U = -μ/r · [1 - Σ Jn·(R_eq/r)^n·Pn(sin φ)]
138 const Scalar correction =
139 J2_coeff * Re_r2 * P2 + J3_coeff * Re_r3 * P3 + J4_coeff * Re_r4 * P4;
140
141 return -mu / r * (1.0 - correction);
142}
143
144} // namespace vulcan::gravity::j2j4
constexpr double R_eq
Equatorial radius [m] (WGS84).
Definition Constants.hpp:16
constexpr double J4
J4 zonal harmonic coefficient.
Definition Constants.hpp:34
constexpr double J3
J3 zonal harmonic coefficient.
Definition Constants.hpp:31
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
Definition J2J4.hpp:9
Scalar potential(const Vec3< Scalar > &r_ecef, double mu=constants::earth::mu, double J2_coeff=constants::earth::J2, double J3_coeff=constants::earth::J3, double J4_coeff=constants::earth::J4, double R_eq=constants::earth::R_eq)
J2/J3/J4 gravitational potential.
Definition J2J4.hpp:108
Vec3< Scalar > acceleration(const Vec3< Scalar > &r_ecef, double mu=constants::earth::mu, double J2_coeff=constants::earth::J2, double J3_coeff=constants::earth::J3, double J4_coeff=constants::earth::J4, double R_eq=constants::earth::R_eq)
J2/J3/J4 gravitational acceleration.
Definition J2J4.hpp:29