8#ifndef __mx_astro_kepler_hpp__
9#define __mx_astro_kepler_hpp__
25#define KEPLER_TOL ( 1e-8 )
30#define KEPLER_ITMAX ( 1000 )
43template <
typename realT>
62 err = e * sinh( curr ) - curr - M;
63 while( fabs( err ) > tol && n_iter < 10000 )
66 curr -= err / ( e * cosh( curr ) - 1. );
67 err = e * sinh( curr ) - curr - M;
70 E = ( is_negative ? -curr : curr );
74 std::cerr <<
"hyperbolic kepler failed to converge e=" << e <<
"\n";
84template <
typename realT>
87 realT cosE, sinE, fi, fi1, fi2, fi3, di1, di2, di3;
93 fi = Ei - e * sinE - M;
99 di2 = -fi / ( fi1 + 0.5 * di1 * fi2 );
100 di3 = -fi / ( fi1 + 0.5 * di2 * fi2 + di2 * di2 * fi3 / 6.0 );
112template <
typename realT>
122 realT lastE, sinE, sign;
129 E = M + 0.85 * e * sign;
131 for( i = 0; i < itmax; i++ )
138 if( i > 1 && fabs( E - lastE ) < tol )
140 D = M - ( E - e * sin( E ) );
155template <
typename realT>
160 realT tol = KEPLER_TOL,
161 long itmax = KEPLER_ITMAX
180template<
typename arithT>
183 arithT cosE0, sinE0, cosdE, sindE, fi, fi1, fi2, fi3, di1, di2, di3;
191 fi = dEi - EC*sindE + ES*(1-cosdE) - dM;
192 fi1 = 1.0 - EC*cosdE + ES*sindE;
193 fi2 = EC*sindE + ES*cosdE;
194 fi3 = EC*cosdE - ES*sindE;
197 di2 = -fi/(fi1 + 0.5*di1*fi2);
198 di3 = -fi/(fi1 + 0.5*di2*fi2 + di2*di2*fi3/6.0);
214template<
typename arithT>
218 arithT lastdE, sindE, sign;
220 sindE = ES*cos(dM-ES) + EC*sin(dM-ES);
222 if(sindE < 0.0) sign = -1.0;
224 (*dE) = dM + 0.85*sign*e-ES;
226 for(i=0; i < itmax; i++)
233 if(i > 0. && fabs((*dE)-lastdE) < tol)
235 (*D) = dM - (*dE - EC*sin(*dE) + ES*(1-cos(*dE)));
277template<
typename arithT>
278int get_W_1pt_z0(arithT &W, arithT x, arithT y, arithT r, arithT f, arithT w)
287 else if(w == DPI - f)
294 W = atan2(sinW, cosW);
278int get_W_1pt_z0(arithT &W, arithT x, arithT y, arithT r, arithT f, arithT w) {
…}
long solve_kepler_danby(realT &E, realT &D, realT e, realT M, realT tol, long itmax)
Solve Kepler's equation using Danby's quartic Newton-Raphson method.
realT kepler_danby_1(realT e, realT M, realT Ei)
Calculate the next iteration of Danby's quartic Newton-Raphson method.
long hyperbolic_kepler(realT &E, realT &err, realT e, realT M, realT tol, long itmax)
Solve the hyperbolic kepler equation (for e> 1).
long solve_kepler(realT &E, realT &D, realT e, realT M, realT tol=KEPLER_TOL, long itmax=KEPLER_ITMAX)
Solve Kepler's equation for any e. Uses solve_kepler_danby if e < 1.0, hyperbolic_kepler otherwise.
arithT kepler_danby_diff_1(arithT EC, arithT ES, arithT dM, arithT dEi)
Calculate the next iteration of Danby's quartic Newton-Raphson method (difference form).
int get_W_1pt_z0(arithT &W, arithT x, arithT y, arithT r, arithT f, arithT w)
Calculate the inclination and the longitude of the ascending node given a point on the orbit projecte...
long solve_keplerdiff_danby(arithT *dE, arithT *D, arithT e, arithT EC, arithT ES, arithT dM, arithT tol, long itmax)
Solve Kepler's equation in difference form using Danby's quartic Newton-Raphson method.
Unit specifications and conversions.