mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Orbital Mechanics

Calculations of orbits and related quantities.

Modules

 The Kepler Problem
 

Functions

template<typename units >
units::realT mx::astro::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. More...
 
template<typename units >
units::realT mx::astro::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. More...
 
template<typename realT >
realT mx::astro::orbitMeanAnol (realT t, realT t0, realT P)
 Calculate the mean anomaly at time t, given the time of pericenter passage t0 and period P.
More...
 
template<typename realT >
long mx::astro::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. More...
 
template<typename realT >
realT mx::astro::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. More...
 
template<typename realT >
realT mx::astro::orbitLambertPhase (realT cos_alf)
 Get the lambertian phase function at orbital phase specified as cos(alfa), where alfa is the phase angle. More...
 
template<typename units >
units::realT mx::astro::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. More...
 
template<typename vectorT , typename realT >
int mx::astro::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. More...
 
template<typename vectorT , typename arithT >
int mx::astro::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 elements and a vector of times. More...
 

Function Documentation

◆ orbitCartesian2DPhi()

template<typename vectorT , typename arithT >
int mx::astro::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 elements and a vector of times.

Template Parameters
vectorTa type whose elements are accessed with the [] operator.
arithTthe type in which to perform arithmetic
Return values
-1on error calculating the orbit (from orbitCartesianWork)
0on success.
Parameters
[out]xthe projected x positions of the orbit. Must be at least as long as t.
[out]ythe projected y positions of the orbit. Must be at least as long as t.
[out]rthe separation of the orbit. Must be at least as long as t.
[out]rProjthe projected separation of the orbit. Must be at least as long as t.
[out]phithe Lambert phase function. Must be at least as long as t.
[in]tthe times at which to calculate the projected positions
[in]Nthe number of points contained in N, and allocated in nx, ny, nz
[in]athe semi-major axis of the orbit
[in]Pthe orbital period
[in]ethe eccentricity of the orbit
[in]t0the time of pericenter passage of the orbit
[in]ithe inclination of the orbit
[in]wthe argument of pericenter of the orbit
[in]Wthe longitude of the ascending node of the orbit.

Definition at line 298 of file orbitUtils.hpp.

References mx::astro::orbitCartesianWork().

◆ orbitCartesianWork()

template<typename vectorT , typename realT >
int mx::astro::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.

Only those quantities with non-null pointers are actually calculated.

The orbital parameters with dimensions, (a, P, and t0) must be in consistent units.

Template Parameters
vectorTa type whose elements are accessed with the [] operator. No other requirements are placed on this type, so it could be a native pointer (i.e. double *).
realTthe type in which to perform calculations. Does not need to match the storage type of vectorT.
Return values
-1on error calculating the orbit (from rf_elements)
0on success.
Parameters
[out]x[optional] If not NULL, will be the projected x positions of the orbit. Must be at least as long as t.
[out]y[optional] If not NULL, will be the projected y positions of the orbit. Must be at least as long as t.
[out]z[optional] If not NULL, will be the projected z positions of the orbit. Must be at least as long as t.
[out]r[optional] If not NULL, will be the separation of the orbit. Must be at least as long as t.
[out]rProj[optional] If not NULL, will be the projected separation of the orbit. Must be at least as long as t.
[out]f[optional] If not NULL, will be the true anomaly of the orbit. Must be at least as long as t.
[out]cos_alf[optional] If not NULL, will be the phase angle of the orbit. Must be at least as long as t.
[out]phi[optional] If not NULL, will be the Lambertian phase function. Must be at least as long as t.
[in]tthe times at which to calculate the projected positions
[in]Nthe number of points contained in t, and allocated in nx, ny, nz. Avoids requiring a size() member (i.e. if vectorT is native pointers).
[in]athe semi-major axis of the orbit.
[in]Pthe orbital period.
[in]ethe eccentricity of the orbit.
[in]t0the time of pericenter passage of the orbit.
[in]ithe inclination of the orbit [radians].
[in]wthe argument of pericenter of the orbit [radians].
[in]Wthe longitude of the ascending node of the orbit [radians].

Definition at line 205 of file orbitUtils.hpp.

References mx::astro::orbitElements(), and mx::astro::orbitMeanAnol().

Referenced by mx::astro::orbitCartesian2DPhi().

◆ orbitElements()

template<typename realT >
long mx::astro::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.

Template Parameters
realTis the type used for arithmetic
Returns
the numer of iterations in solving Kepler's equation, if successful.
-1 if itmax is exceeded.
Parameters
[out]ris the orbital separation
[out]fis the true anomaly
[out]Eis the eccentric anomaly, provided since it is free
[out]Dis the error after the last iteration of the Kepler solution.
[in]eis the eccentricity
[in]Mis the mean anomaly
[in]ais the semi-major axis
[in]tolis the desired tolerance
[in]itmaxis the maximum number of iterations

Definition at line 81 of file orbitUtils.hpp.

References mx::astro::solve_kepler().

Referenced by mx::astro::orbitCartesianWork().

◆ orbitLambertPhase()

template<typename realT >
realT mx::astro::orbitLambertPhase ( realT  cos_alf)

Get the lambertian phase function at orbital phase specified as cos(alfa), where alfa is the phase angle.

Uses cos(alfa) to save an operation after calculating orbit phase.

Template Parameters
realTis the type used for arithmetic
Returns
the lambert phase function at alpha
Parameters
[in]cos_alfthe cosine of the phase angle

Definition at line 158 of file orbitUtils.hpp.

◆ orbitMeanAnol()

template<typename realT >
realT mx::astro::orbitMeanAnol ( realT  t,
realT  t0,
realT  P 
)

Calculate the mean anomaly at time t, given the time of pericenter passage t0 and period P.

Definition at line 63 of file orbitUtils.hpp.

Referenced by mx::astro::orbitCartesianWork().

◆ orbitPeriod()

template<typename units >
units::realT mx::astro::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.

Template Parameters
unitsspecifies the unit system and precision, see Unit Conversions.
Returns
the period in the specified units
Parameters
[in]m1mass of one object.
[in]m2mass of the other object (can be 0).
[in]athe semi-major axis of the orbit.

Definition at line 28 of file orbitUtils.hpp.

◆ orbitPhaseCosine()

template<typename realT >
realT mx::astro::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.

Only calculates cos(alfa) to save an operation when possible.

Template Parameters
realTis the type used for arithmetic
Returns
the cosine of the phase angle
Parameters
[in]fis the true anomoaly at which to calculate alfa
[in]wthe argument of pericenter of the orbit
[in]incis the inclinatin of the orbit

Definition at line 140 of file orbitUtils.hpp.

◆ orbitRV()

template<typename units >
units::realT mx::astro::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.

Returns
the radial velocity of the body with mass m1 as it orbits the barycenter of its orbit w.r.t. m2.
Parameters
[in]m1the mass of the body for which the RV is computed
[in]m2the mass of the other body in the orbiting pair
[in]incthe inclination of the orbit of m2.
[in]athe semi-major axis of the orbit
[in]ethe eccentricity of the orbit
[in]wthe argument of pericenter
[in]fthe true anomaly at which the RV is to be calculated.

Definition at line 170 of file orbitUtils.hpp.

◆ orbitSemiMaj()

template<typename units >
units::realT mx::astro::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.

Template Parameters
unitsspecifies the unit system and precision, see Unit Conversions.
Returns
the semi-major axis in the specified units
Parameters
[in]m1mass of one object.
[in]m2mass of the other object (can be 0).
[in]Pthe period of the orbit.

Definition at line 46 of file orbitUtils.hpp.