KrisLibrary  1.0.0
angle.h
Go to the documentation of this file.
1 #ifndef MATH_ANGLE_H
2 #define MATH_ANGLE_H
3 
4 #include "math.h"
5 
11 namespace Math {
15 Real AngleNormalize(Real a);
18 Real AngleDiff(Real a, Real b);
20 Real AngleCCWDiff(Real a, Real b);
22 Real AngleInterp(Real a, Real b, Real u);
23 inline bool IsValidAngle(Real a);
24 
34 {
35  void setPoint(Real a) { c=a; d=0; }
37  void setRange(Real a, Real b);
39  void setMinRange(Real a, Real b);
40  inline void setEmpty() { c=Inf; d=0; }
41  inline void setCircle() { c=0; d=TwoPi; }
42  void setCompliment(const AngleInterval& i);
45  void setIntersection(const AngleInterval& i1, const AngleInterval& i2);
48  void setUnion(const AngleInterval& i1, const AngleInterval& i2);
49  void setCosGreater(Real y);
50  void setSinGreater(Real y);
51  void setCosLess(Real y);
52  void setSinLess(Real y);
53 
54  void inplaceCompliment();
55  inline void inplaceIntersection(const AngleInterval& i) {
56  AngleInterval j=*this;
57  setIntersection(i,j);
58  }
59  inline void inplaceUnion(const AngleInterval& i) {
60  AngleInterval j=*this;
61  setUnion(i,j);
62  }
63  inline void inplaceShift(Real theta) { c = AngleNormalize(c+theta); }
64 
65  bool contains(Real a) const;
66  bool contains(const AngleInterval& i) const;
67  bool intersects(const AngleInterval& i) const;
68  void normalize();
69  Real clamp(Real a) const;
70 
71  inline bool isEmpty() const { return c==Inf; }
72  inline bool isFull() const { return d>=TwoPi; }
73  inline bool isPoint() const { return d==0; }
74 
75  Real c,d;
76 };
77 
79 inline void Acos_All(Real x,Real& a,Real& b) { a=Acos(x); b=TwoPi-a; }
81 inline void Asin_All(Real x,Real& a,Real& b) { a=Asin(x); b=Pi-a; a=AngleNormalize(a); }
83 inline void Atan_All(Real x,Real& a,Real& b) { a=Atan(x); b=AngleNormalize(a+Pi); a=AngleNormalize(a); }
84 
87 void TransformCosSin_Cos(Real a,Real b,Real& c,Real& d);
89 void TransformCosSin_Sin(Real a,Real b,Real& c,Real& d);
90 
93 bool SolveCosSinEquation(Real a,Real b,Real c,Real& t1,Real& t2);
94 
96 void SolveCosSinGreater(Real a,Real b,Real c,AngleInterval& i);
97 
99 } //namespace Math
100 
101 #endif
Common math typedefs, constants, functions.
void Asin_All(Real x, Real &a, Real &b)
returns all solutions y to sin(y)=x in a,b
Definition: angle.h:81
void setSinGreater(Real y)
set the range [a,b] of x s.t. sin(x) >= y
Definition: angle.cpp:194
Real AngleDiff(Real a, Real b)
Returns the closest distance to get to a from b (range [-pi,pi])
Definition: angle.cpp:20
Real AngleNormalize(Real a)
Normalizes an angle to [0,2pi)
Definition: angle.cpp:13
Real AngleInterp(Real a, Real b, Real u)
Interpolates between rotations a and b (u from 0 to 1)
Definition: angle.cpp:34
void setMinRange(Real a, Real b)
sets the smallest range containing both a and b
Definition: angle.cpp:53
void setCosGreater(Real y)
set the range [a,b] of x s.t. cos(x) >= y
Definition: angle.cpp:183
void TransformCosSin_Sin(Real a, Real b, Real &c, Real &d)
Same as above, but returns c*sin(x+d)
Definition: angle.cpp:247
void setIntersection(const AngleInterval &i1, const AngleInterval &i2)
Definition: angle.cpp:60
A contiguous range of angles.
Definition: angle.h:33
void setRange(Real a, Real b)
sets the range from a CCW to b
Definition: angle.cpp:47
void TransformCosSin_Cos(Real a, Real b, Real &c, Real &d)
Definition: angle.cpp:226
void Atan_All(Real x, Real &a, Real &b)
returns all solutions y to tan(y)=x in a,b
Definition: angle.h:83
void setUnion(const AngleInterval &i1, const AngleInterval &i2)
Definition: angle.cpp:94
void setCosLess(Real y)
set the range [a,b] of x s.t. cos(x) <= y
Definition: angle.cpp:205
Real AngleCCWDiff(Real a, Real b)
Returns the CCW distance needed to get to a from b.
Definition: angle.cpp:28
void setSinLess(Real y)
set the range [a,b] of x s.t. sin(x) <= y
Definition: angle.cpp:215
bool SolveCosSinEquation(Real a, Real b, Real c, Real &t1, Real &t2)
Definition: angle.cpp:268
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
void SolveCosSinGreater(Real a, Real b, Real c, AngleInterval &i)
Same as above, but a cos(x) + b sin(x) >= c.
Definition: angle.cpp:290
void Acos_All(Real x, Real &a, Real &b)
returns all solutions y to cos(y)=x in a,b
Definition: angle.h:79