Angle.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_ANGLE_HH_
18 #define IGNITION_MATH_ANGLE_HH_
19 
20 #include <iostream>
21 #include <ignition/math/Helpers.hh>
22 #include <ignition/math/config.hh>
23 
27 #define IGN_RTOD(r) ((r) * 180 / IGN_PI)
28 
32 #define IGN_DTOR(d) ((d) * IGN_PI / 180)
33 
37 #define IGN_NORMALIZE(a) (atan2(sin(a), cos(a)))
38 
39 namespace ignition
40 {
41  namespace math
42  {
43  inline namespace IGNITION_MATH_VERSION_NAMESPACE
44  {
47  class IGNITION_MATH_VISIBLE Angle
48  {
50  public: static const Angle Zero;
51 
53  public: static const Angle Pi;
54 
56  public: static const Angle HalfPi;
57 
59  public: static const Angle TwoPi;
60 
62  public: Angle();
63 
66  // cppcheck-suppress noExplicitConstructor
67  public: Angle(const double _radian);
68 
71  public: Angle(const Angle &_angle);
72 
74  public: virtual ~Angle();
75 
78  public: void Radian(double _radian);
79 
82  public: void Degree(double _degree);
83 
86  public: double Radian() const;
87 
90  public: double Degree() const;
91 
93  public: void Normalize();
94 
97  public: double operator()() const;
98 
101  public: inline double operator*() const
102  {
103  return value;
104  }
105 
109  public: Angle operator-(const Angle &_angle) const;
110 
114  public: Angle operator+(const Angle &_angle) const;
115 
119  public: Angle operator*(const Angle &_angle) const;
120 
124  public: Angle operator/(const Angle &_angle) const;
125 
129  public: Angle operator-=(const Angle &_angle);
130 
134  public: Angle operator+=(const Angle &_angle);
135 
139  public: Angle operator*=(const Angle &_angle);
140 
144  public: Angle operator/=(const Angle &_angle);
145 
149  public: bool operator==(const Angle &_angle) const;
150 
154  public: bool operator!=(const Angle &_angle) const;
155 
159  public: bool operator<(const Angle &_angle) const;
160 
164  public: bool operator<=(const Angle &_angle) const;
165 
169  public: bool operator>(const Angle &_angle) const;
170 
174  public: bool operator>=(const Angle &_angle) const;
175 
180  public: friend std::ostream &operator<<(std::ostream &_out,
181  const ignition::math::Angle &_a)
182  {
183  _out << _a.Radian();
184  return _out;
185  }
186 
191  public: friend std::istream &operator>>(std::istream &_in,
192  ignition::math::Angle &_a)
193  {
194  // Skip white spaces
195  _in.setf(std::ios_base::skipws);
196  _in >> _a.value;
197  return _in;
198  }
199 
201  private: double value;
202  };
203  }
204  }
205 }
206 
207 #endif
static const Angle TwoPi
math::Angle(IGN_PI * 2)
Definition: Angle.hh:59
static const Angle HalfPi
math::Angle(IGN_PI * 0.5)
Definition: Angle.hh:56
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Angle &_a)
Stream insertion operator.
Definition: Angle.hh:180
An angle and related functions.
Definition: Angle.hh:47
friend std::istream & operator>>(std::istream &_in, ignition::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:191
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:50
double operator*() const
Dereference operator.
Definition: Angle.hh:101
Definition: Angle.hh:39
static const Angle Pi
math::Angle(IGN_PI)
Definition: Angle.hh:53