8 #ifndef mx_astro_orbitUtils_hpp
9 #define mx_astro_orbitUtils_hpp
11 #include "../math/constants.hpp"
27 template<
typename units>
29 typename units::realT m2,
30 typename units::realT a
33 return math::two_pi<typename units::realT>()* sqrt( (a*a*a) / (constants::G<units>()*(m1+m2)));
45 template<
typename units>
47 typename units::realT m2,
48 typename units::realT P
51 typedef typename units::realT realT;
53 constexpr realT two =
static_cast<realT
>(2);
55 return pow( pow(P/(math::two_pi<realT>()),two) * constants::G<units>() *(m1+m2), math::third<realT>());
62 template<
typename realT>
68 return math::two_pi<realT>()*(t-t0)/P;
80 template<
typename realT>
89 long itmax=KEPLER_ITMAX
96 std::cerr <<
"e < 0 in rf_elements\n";
102 std::cerr <<
"e = 1 in rf_elements, which is not currently handled.\n";
110 f = 2.0*std::atan(std::sqrt((e+1.0)/(e-1.0))*std::tanh(E/2.0));
111 r = a*(1.0-e*std::cosh(E));
122 f = 2.0*std::atan(std::sqrt((1.0+e)/(1.0-e))*std::tan(E/2.0));
123 r = a * (1.0-e*std::cos(E));
139 template<
typename realT>
145 return sin(f+w)*sin(inc);
157 template<
typename realT>
160 realT alf = std::acos(cos_alf);
161 return (sin(alf) + (math::pi<realT>()-alf)*cos_alf)/math::pi<realT>();
169 template<
typename units>
170 typename units::realT
orbitRV(
typename units::realT m1,
171 typename units::realT m2,
172 typename units::realT inc,
173 typename units::realT a,
174 typename units::realT e,
175 typename units::realT w,
176 typename units::realT f
179 typedef typename units::realT realT;
181 realT msini = m2*sin(inc);
183 realT rv = (msini)*std::sqrt((constants::G<units>()/(m1+m2))/(a*(1-e*e)));
185 rv *= (std::cos(w+f) + e*std::cos(w));
204 template<
typename vectorT,
typename realT>
225 realT _M, _r, _f, _E, _D;
228 realT cos_i = cos(i);
229 realT sin_i = sin(i);
230 realT cos_W = cos(W);
231 realT sin_W = sin(W);
233 realT cos_wf, sin_wf;
235 for(
size_t j=0; j < N; j++)
241 if(rv < 0)
return -1;
248 if(x) (*x)[j] = _r*(cos_W*cos_wf-sin_W*sin_wf*cos_i);
249 if(y) (*y)[j] = _r*(sin_W*cos_wf+cos_W*sin_wf*cos_i);
250 if(z) (*z)[j] = _r*sin_wf*sin_i;
256 (*rProj)[j] = sqrt((*x)[j]*(*x)[j] + (*y)[j]*(*y)[j]);
260 realT _y = _r*(sin_W*cos_wf+cos_W*sin_wf*cos_i);
261 (*rProj)[j] = sqrt((*x)[j]*(*x)[j] + _y*_y);
265 realT _x = _r*(cos_W*cos_wf-sin_W*sin_wf*cos_i);
266 (*rProj)[j] = sqrt( _x*_x + (*y)[j]*(*y)[j]);
270 realT _x = _r*(cos_W*cos_wf-sin_W*sin_wf*cos_i);
271 realT _y = _r*(sin_W*cos_wf+cos_W*sin_wf*cos_i);
272 (*rProj)[j] = sqrt( _x*_x + _y*_y);
278 if(cos_alf) (*cos_alf)[j] = sin_wf*sin_i;
280 if(phi) (*phi)[j] = orbitLambertPhase<realT>(sin_wf*sin_i);
297 template<
typename vectorT,
typename arithT>
314 return orbitCartesianWork(&x, &y, (vectorT *)0, &r, &rProj, (vectorT *)0, (vectorT *)0, &phi, t, N, a, P, e, t0, i, w, W);
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.
realT orbitPhaseCosine(realT f, realT w, realT inc)
Get the orbital phase at true anomaly f. Calculates the cos(alfa) where alfa is the orbital phase.
realT orbitLambertPhase(realT cos_alf)
Get the lambertian phase function at orbital phase specified as cos(alfa), where alfa is the phase an...
units::realT orbitRV(typename units::realT m1, typename units::realT m2, typename units::realT inc, typename units::realT a, typename units::realT e, typename units::realT w, typename units::realT f)
Calculate the radial velocity of an orbiting body inclined relative to an observer.
units::realT orbitSemiMaj(typename units::realT m1, typename units::realT m2, typename units::realT P)
Calculate the semi-major axis of an orbit, given the masses and Period, using SI units.
int orbitCartesianWork(vectorT *x, vectorT *y, vectorT *z, vectorT *r, vectorT *rProj, vectorT *f, vectorT *cos_alf, vectorT *phi, const vectorT &t, const size_t N, realT a, realT P, realT e, realT t0, realT i, realT w, realT W)
Calculate various quantities of an orbit given the keplerian elements and a vector of times.
long orbitElements(realT &r, realT &f, realT E, realT D, realT e, realT M, realT a, realT tol=KEPLER_TOL, long itmax=KEPLER_ITMAX)
Calculate the separation and true anomaly for an orbit at the specified mean anomaly.
int orbitCartesian2DPhi(vectorT &x, vectorT &y, vectorT &r, vectorT &rProj, vectorT &phi, const vectorT &t, const size_t N, arithT a, arithT P, arithT e, arithT t0, arithT i, arithT w, arithT W)
Calculate the cartesian x-y position and the Lambert phase function of an orbit given Keplerian eleme...
units::realT orbitPeriod(typename units::realT m1, typename units::realT m2, typename units::realT a)
Calculate the period of an orbit, given the masses and semi-major axis.
realT orbitMeanAnol(realT t, realT t0, realT P)
Calculate the mean anomaly at time t, given the time of pericenter passage t0 and period P.
Declarations for the utilities related to the Kepler problem.