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

Functions for basic geometry and working with earth coordinate systems

Functions

template<typename realT >
realT mx::math::dtor (realT q)
 Convert from degrees to radians. More...
 
template<typename realT >
realT mx::math::rtod (realT q)
 Convert from radians to degrees. More...
 
template<class angleT >
angleT::realT mx::math::angleMod (typename angleT::realT q)
 Calculate the angle modulo full-circle, normalizing to a positive value. More...
 
template<class angleT >
angleT::realT mx::math::angleDiff (typename angleT::realT q1, typename angleT::realT q2)
 Calculate the difference between two angles, correctly across 0/360. More...
 
template<class angleT >
angleT::realT mx::math::angleMean (const std::vector< typename angleT::realT > &q)
 Calculate the mean of a set of angles, correctly across 0/360. More...
 
template<int degrad = 0, typename realT >
int mx::math::continueAngles (std::vector< realT > &angles, realT threshold=0.75)
 Make a vector of angles continuous, fixing the 0/360 crossing. More...
 
template<typename realT >
void mx::math::rotatePoint (realT &x0, realT &y0, realT angle)
 Rotate a point about the origin. More...
 

Function Documentation

◆ angleDiff()

template<class angleT >
angleT::realT mx::math::angleDiff ( typename angleT::realT  q1,
typename angleT::realT  q2 
)

Calculate the difference between two angles, correctly across 0/360.

Calculates \( dq = q2- q1 \), but accounts for crossing 0/360. This implies that \( dq \le 180 \).

Returns
the difference of q2 and q1
Template Parameters
degradcontrols whether this is in degrees (0, default) or radians (1)
realTis the type in which to do arithmetic
Test:
Verify compilation and calculations of math::angleDiff [test doc]
Parameters
[in]q1angle to subtract from q2, in degrees.
[in]q2angle to subtract q1 from, in degrees.

Definition at line 191 of file geo.hpp.

◆ angleMean()

template<class angleT >
angleT::realT mx::math::angleMean ( const std::vector< typename angleT::realT > &  q)

Calculate the mean of a set of angles, correctly across 0/360.

Calculates the mean by decomposing into vectors and averaging the components. This accounts for crossing 0/360.

Returns
the mean angle
Template Parameters
angleTis the angle type, either radians<realT> or degrees<realT>. angleT::realT is the type in which to do arithmetic.
Parameters
[in]qvector of angles to average.

Definition at line 227 of file geo.hpp.

◆ angleMod()

template<class angleT >
angleT::realT mx::math::angleMod ( typename angleT::realT  q)

Calculate the angle modulo full-circle, normalizing to a positive value.

The output will be betweeen 0 and 360 (or 0 and 2pi).

Returns
the value of q normalized to 0 <= q < 360[2pi]
Template Parameters
degradcontrols whether this is in degrees (0, default) or radians (1)
realTis the type in which to do arithmetic
Parameters
[in]qthe angle

Definition at line 163 of file geo.hpp.

◆ continueAngles()

template<int degrad = 0, typename realT >
int mx::math::continueAngles ( std::vector< realT > &  angles,
realT  threshold = 0.75 
)

Make a vector of angles continuous, fixing the 0/360 crossing.

The vector is modified so it is continuous.

Template Parameters
degradcontrols whether angles are degrees (false) or radians (true)
realTis the type in which to do arithmetic
Parameters
[in]anglesthe vector of angles
[in]threshold[optional] the fraction of a full circle at which to consider a difference in angle discontinuous.

Definition at line 257 of file geo.hpp.

◆ dtor()

template<typename realT >
realT mx::math::dtor ( realT  q)

Convert from degrees to radians.

Parameters
qis the angle to convert
Returns
the angle q converted to radians
Test:
Verify compilation and calculations of math::angleDiff [test doc]

Definition at line 132 of file geo.hpp.

Referenced by mx::improc::azBoxKernel< _arrayT, _kernW >::azBoxKernel(), mx::improc::ADIDerotator< _realT >::derotAngle(), mx::astro::parAngDeg(), mx::improc::KLIPreduction< _realT, _derotFunctObj, _evCalcT >::regions(), and SCENARIO().

◆ rotatePoint()

template<typename realT >
void mx::math::rotatePoint ( realT &  x0,
realT &  y0,
realT  angle 
)

Rotate a point about the origin.

The rotation is counter-clockwise for positive angles.

Template Parameters
realTa real floating point type
Parameters
x0[in.out] the x-coordinate of the point to rotate. On exit contains the rotated value.
y0[in.out] the y-coordinate of the point to rotate. On exit contains the rotated value.
[in]anglethe angle by which to rotate [radians]

Definition at line 304 of file geo.hpp.

◆ rtod()

template<typename realT >
realT mx::math::rtod ( realT  q)

Convert from radians to degrees.

Parameters
qis the angle to convert
Returns
the angle q converted to degrees

Definition at line 147 of file geo.hpp.

Referenced by mx::improc::imCenterRadon< transformT >::center(), and mx::astro::parAngDeg().