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

Functions for basic geometry and working with earth coordinate systems

Macros

#define semilatrect(a, e)
 Calculate the semi-latus rectum of a conic section.
#define focus(a, e)
 Calculate the focal parameter of a conic section.
#define semimaj(p, e)
#define eccent(a, p)

Functions

template<typename realT>
realT mx::math::dtor (realT q)
 Convert from degrees to radians.
template<typename realT>
realT mx::math::rtod (realT q)
 Convert from radians to degrees.
template<class angleT>
angleT::realT mx::math::angleMod (typename angleT::realT q)
 Calculate the angle modulo full-circle, normalizing to a positive value.
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.
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.
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.
template<typename realT>
void mx::math::rotatePoint (realT &x0, realT &y0, realT angle)
 Rotate a point about the origin.

Macro Definition Documentation

◆ eccent

#define eccent ( a,
p )
Value:
( a == 0.0 ? 1e34 \
: ( p >= 1e9 ? 0.0 \
: ( p > 0 ? ( -p / ( 2 * a ) + 0.5 * std::sqrt( p * p / ( a * a ) + 4 ) ) \
: ( p / ( 2 * a ) + 0.5 * std::sqrt( p * p / ( a * a ) + 4 ) ) ) ) )

Calculate the eccentricity of a conic section given the semi-major axis and the focal parameter

Definition at line 67 of file geo.hpp.

◆ focus

#define focus ( a,
e )
Value:
( e == 0.0 ? 1e34 : ( e == 1.0 ? 2. * a : ( e < 1. ? a * ( 1 - e * e ) / e : a * ( e * e - 1 ) / e ) ) )

Calculate the focal parameter of a conic section.

Definition at line 52 of file geo.hpp.

◆ semilatrect

#define semilatrect ( a,
e )
Value:
( e == 0.0 ? a : ( e == 1.0 ? 2. * a : ( e < 1. ? a * ( 1 - e * e ) : a * ( e * e - 1 ) ) ) )

Calculate the semi-latus rectum of a conic section.

Definition at line 45 of file geo.hpp.

◆ semimaj

#define semimaj ( p,
e )
Value:
( e == 1.0 ? 1e34 : ( e < 1 ? p * e / ( 1 - e * e ) : p * e / ( e * e - 1 ) ) )

Calculate the semi-major axis of a conic section, given the focal parameter and the eccentricity

Definition at line 60 of file geo.hpp.

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
angleTcontrols whether this is in degrees (0, default) or radians (1)
realTis the type in which to do arithmetic
Parameters
[in]q1angle to subtract from q2.
[in]q2angle to subtract q1 from.

Definition at line 191 of file geo.hpp.

Referenced by mx::improc::annulusCoordsWorker(), mx::improc::maskWedge(), mx::improc::azBoxKernel< _arrayT, _kernW, _verboseT >::setKernel(), and TEST_CASE().

◆ 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 226 of file geo.hpp.

Referenced by mx::improc::annulusBoundingRect().

◆ 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 164 of file geo.hpp.

Referenced by mx::improc::annulusCoordsWorker(), and TEST_CASE().

◆ 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 255 of file geo.hpp.

References two_pi().

◆ 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

Definition at line 133 of file geo.hpp.

Referenced by mx::improc::azBoxKernel< _arrayT, _kernW, _verboseT >::azBoxKernel(), mx::sigproc::makeModifiedFourierMode(), mx::astro::parAngDeg(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and unitTest::improcTest::imageFiltersTest::TEST_CASE().

◆ 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 310 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 148 of file geo.hpp.

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