34#include "constants.hpp"
45#define semilatrect( a, e ) \
46 ( e == 0.0 ? a : ( e == 1.0 ? 2. * a : ( e < 1. ? a * ( 1 - e * e ) : a * ( e * e - 1 ) ) ) )
52#define focus( a, e ) \
53 ( e == 0.0 ? 1e34 : ( e == 1.0 ? 2. * a : ( e < 1. ? a * ( 1 - e * e ) / e : a * ( e * e - 1 ) / e ) ) )
60#define semimaj( p, e ) ( e == 1.0 ? 1e34 : ( e < 1 ? p * e / ( 1 - e * e ) : p * e / ( e * e - 1 ) ) )
67#define eccent( a, p ) \
70 : ( p > 0 ? ( -p / ( 2 * a ) + 0.5 * std::sqrt( p * p / ( a * a ) + 4 ) ) \
71 : ( p / ( 2 * a ) + 0.5 * std::sqrt( p * p / ( a * a ) + 4 ) ) ) ) )
86template <
typename degrad,
typename realT>
93template <
typename _realT>
97 static constexpr realT scale =
99 static constexpr realT degrees = 1;
100 static constexpr realT radians =
pi<realT>() /
static_cast<realT
>( 180 );
101 static constexpr realT full =
static_cast<realT
>( 360.0 );
102 static constexpr realT half =
static_cast<realT
>( 180.0 );
105template <
typename realT>
112template <
typename _realT>
116 static constexpr realT scale = 1;
117 static constexpr realT degrees =
static_cast<realT
>( 180 ) /
pi<realT>();
118 static constexpr realT radians = 1;
120 static constexpr realT half =
pi<realT>();
123template <
typename realT>
137template <
typename realT>
152template <
typename realT>
168template <
class angleT>
169typename angleT::realT
angleMod(
typename angleT::realT
q )
171 static_assert( std::is_floating_point<typename angleT::realT>::value,
172 "angleMod: angleT::realT must be floating point" );
174 q =
fmod(
q, angleT::full );
196template <
class angleT>
198 typename angleT::realT
q2
201 static_assert( std::is_floating_point<typename angleT::realT>::value,
"angleDiff: realT must be floating point" );
203 typename angleT::realT
dq =
q2 -
q1;
205 if( std::abs(
dq ) > angleT::half )
209 dq =
dq +
static_cast<typename angleT::realT
>( 2 ) * angleT::half;
213 dq =
dq -
static_cast<typename angleT::realT
>( 2 ) * angleT::half;
230template <
class angleT>
231typename angleT::realT
234 static_assert( std::is_floating_point<typename angleT::realT>::value,
"angleMean: realT must be floating point" );
236 typename angleT::realT
s = 0;
237 typename angleT::realT c = 0;
239 for(
int i = 0;
i <
q.size(); ++
i )
241 s +=
sin(
q[
i] / angleT::scale );
242 c +=
cos(
q[
i] / angleT::scale );
248 return atan2(
s, c ) * angleT::scale;
260template <
int degrad = 0,
typename realT>
262 realT threshold = 0.75
271 full =
static_cast<realT
>( 360 );
315template <
typename realT>
324 realT
cq =
cos( angle );
325 realT
sq =
sin( angle );
constexpr floatT six_fifths()
Return 6/5 in the specified precision.
int continueAngles(std::vector< realT > &angles, realT threshold=0.75)
Make a vector of angles continuous, fixing the 0/360 crossing.
angleT::realT angleDiff(typename angleT::realT q1, typename angleT::realT q2)
Calculate the difference between two angles, correctly across 0/360.
angleT::realT angleMod(typename angleT::realT q)
Calculate the angle modulo full-circle, normalizing to a positive value.
realT rtod(realT q)
Convert from radians to degrees.
angleT::realT angleMean(const std::vector< typename angleT::realT > &q)
Calculate the mean of a set of angles, correctly across 0/360.
realT dtor(realT q)
Convert from degrees to radians.
void rotatePoint(realT &x0, realT &y0, realT angle)
Rotate a point about the origin.
Type holding constants related to angle calculations in degrees.