All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
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_ANGLE_HH_
18 #define _IGNITION_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  public: Angle(double _radian);
64 
67  public: Angle(const Angle &_angle);
68 
70  public: virtual ~Angle();
71 
74  public: void Radian(double _radian);
75 
78  public: void Degree(double _degree);
79 
82  public: double Radian() const;
83 
86  public: double Degree() const;
87 
89  public: void Normalize();
90 
93  public: inline double operator*() const
94  {
95  return value;
96  }
97 
101  public: Angle operator-(const Angle &_angle) const;
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);
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: bool operator==(const Angle &_angle) const;
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 
172  public: friend std::ostream &operator<<(std::ostream &_out,
173  const ignition::math::Angle &_a)
174  {
175  _out << _a.Radian();
176  return _out;
177  }
178 
183  public: friend std::istream &operator>>(std::istream &_in,
185  {
186  // Skip white spaces
187  _in.setf(std::ios_base::skipws);
188  _in >> _a.value;
189  return _in;
190  }
191 
193  private: double value;
194  };
195  }
196 }
197 
198 #endif
An angle and related functions.
Definition: Angle.hh:44
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:346
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:172
double operator*() const
Dereference operator.
Definition: Angle.hh:93
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.
friend std::istream & operator>>(std::istream &_in, ignition::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:183
static const Angle Pi
math::Angle(IGN_PI)
Definition: Angle.hh:50