34 #include "constants.hpp"
47 #define semilatrect(a,e) (e == 0.0 ? a : (e == 1.0 ? 2.*a : (e < 1. ? a*(1-e*e) : a*(e*e-1))))
53 #define focus(a,e) (e == 0.0 ? 1e34 : (e == 1.0 ? 2.*a : (e < 1. ? a*(1-e*e)/e : a*(e*e-1)/e)))
59 #define semimaj(p,e) (e == 1.0 ? 1e34 : (e < 1 ? p*e/(1-e*e) : p*e/(e*e-1) ))
65 #define eccent(a, p) (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)) ) ))
80 template<
typename degrad,
typename realT>
87 template<
typename _realT>
91 static constexpr realT scale =
static_cast<realT
>(180)/pi<realT>();
92 static constexpr realT degrees = 1;
93 static constexpr realT radians = pi<realT>()/
static_cast<realT
>(180);
94 static constexpr realT full =
static_cast<realT
>(360.0);
95 static constexpr realT half =
static_cast<realT
>(180.0);
98 template<
typename realT>
105 template<
typename _realT>
108 typedef _realT realT;
109 static constexpr realT scale = 1;
110 static constexpr realT degrees =
static_cast<realT
>(180)/pi<realT>();
111 static constexpr realT radians = 1;
112 static constexpr realT full = two_pi<realT>();
113 static constexpr realT half = pi<realT>();
116 template<
typename realT>
131 template<
typename realT>
146 template<
typename realT>
162 template<
class angleT>
163 typename angleT::realT
angleMod(
typename angleT::realT q )
165 static_assert(std::is_floating_point<typename angleT::realT>::value,
"angleMod: angleT::realT must be floating point");
167 q = fmod(q, angleT::full);
169 if(q < 0) q += angleT::full;
190 template<
class angleT>
191 typename angleT::realT
angleDiff(
typename angleT::realT q1,
192 typename angleT::realT q2
197 static_assert(std::is_floating_point<typename angleT::realT>::value,
"angleDiff: realT must be floating point");
199 typename angleT::realT dq = q2-q1;
201 if(std::abs(dq) > angleT::half)
205 dq = dq +
static_cast<typename angleT::realT
>(2)*angleT::half;
209 dq = dq -
static_cast<typename angleT::realT
>(2)*angleT::half;
226 template<
class angleT>
227 typename angleT::realT
angleMean(
const std::vector<typename angleT::realT> & q )
229 static_assert(std::is_floating_point<typename angleT::realT>::value,
"angleMean: realT must be floating point");
231 typename angleT::realT s = 0;
232 typename angleT::realT
c = 0;
234 for(
int i=0; i< q.size(); ++i)
236 s += sin( q[i]/angleT::scale);
237 c += cos( q[i]/angleT::scale );
243 return atan2(s,
c)*angleT::scale ;
256 template<
int degrad = 0,
typename realT>
263 if(degrad) full = two_pi<realT>();
264 else full =
static_cast<realT
>(360);
270 if( fabs(angles[1] - angles[0]) > threshold)
272 if( angles[1] > angles[0]) adj = -full;
278 if(angles.size() == 2)
return 0;
280 for(
int i=2; i< angles.size(); ++i)
284 if( fabs(angles[i] - angles[i-1]) > threshold)
286 if( angles[i] > angles[i-1]) adj += -full;
303 template<
typename realT>
312 realT cq = cos(angle);
313 realT sq = sin(angle);
constexpr units::realT c()
The speed of light.
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.