Angle.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 
26 #define IGN_RTOD(r) ((r) * 180 / IGN_PI)
27 
31 #define IGN_DTOR(d) ((d) * IGN_PI / 180)
32 
36 #define IGN_NORMALIZE(a) (atan2(sin(a), cos(a)))
37 
38 namespace ignition
39 {
40  namespace math
41  {
45  {
47  public: static const Angle Zero;
48 
50  public: static const Angle Pi;
51 
53  public: static const Angle HalfPi;
54 
56  public: static const Angle TwoPi;
57 
59  public: Angle();
60 
63  // cppcheck-suppress noExplicitConstructor
64  public: Angle(const double _radian);
65 
68  public: Angle(const Angle &_angle);
69 
71  public: virtual ~Angle();
72 
75  public: void Radian(double _radian);
76 
79  public: void Degree(double _degree);
80 
83  public: double Radian() const;
84 
87  public: double Degree() const;
88 
90  public: void Normalize();
91 
94  public: double operator()() const;
95 
98  public: inline double operator*() const
99  {
100  return value;
101  }
102 
106  public: Angle operator-(const Angle &_angle) const;
107 
111  public: Angle operator+(const Angle &_angle) const;
112 
116  public: Angle operator*(const Angle &_angle) const;
117 
121  public: Angle operator/(const Angle &_angle) const;
122 
126  public: Angle operator-=(const Angle &_angle);
127 
131  public: Angle operator+=(const Angle &_angle);
132 
136  public: Angle operator*=(const Angle &_angle);
137 
141  public: Angle operator/=(const Angle &_angle);
142 
146  public: bool operator==(const Angle &_angle) const;
147 
151  public: bool operator!=(const Angle &_angle) const;
152 
156  public: bool operator<(const Angle &_angle) const;
157 
161  public: bool operator<=(const Angle &_angle) const;
162 
166  public: bool operator>(const Angle &_angle) const;
167 
171  public: bool operator>=(const Angle &_angle) const;
172 
177  public: friend std::ostream &operator<<(std::ostream &_out,
178  const ignition::math::Angle &_a)
179  {
180  _out << _a.Radian();
181  return _out;
182  }
183 
188  public: friend std::istream &operator>>(std::istream &_in,
190  {
191  // Skip white spaces
192  _in.setf(std::ios_base::skipws);
193  _in >> _a.value;
194  return _in;
195  }
196 
198  private: double value;
199  };
200  }
201 }
202 
203 #endif
An angle and related functions.
Definition: Angle.hh:44
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:47
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Angle &_a)
Stream insertion operator.
Definition: Angle.hh:177
double operator*() const
Dereference operator.
Definition: Angle.hh:98
static const Angle TwoPi
math::Angle(IGN_PI * 2)
Definition: Angle.hh:56
static const Angle HalfPi
math::Angle(IGN_PI * 0.5)
Definition: Angle.hh:53
void Radian(double _radian)
Set the value from an angle in radians.
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: System.hh:59
friend std::istream & operator>>(std::istream &_in, ignition::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:188
Definition: Angle.hh:38
static const Angle Pi
math::Angle(IGN_PI)
Definition: Angle.hh:50