All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Angle.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 /* Desc: Angle class
18  * Author: Nate Koenig
19  * Date: 18 Aug 2008
20  */
21 
22 #ifndef _ANGLE_HH_
23 #define _ANGLE_HH_
24 
25 #include <math.h>
26 #include <iostream>
27 
31 #define GZ_RTOD(r) ((r) * 180 / M_PI)
32 
36 #define GZ_DTOR(d) ((d) * M_PI / 180)
37 
41 #define GZ_NORMALIZE(a) (atan2(sin(a), cos(a)))
42 
43 namespace gazebo
44 {
46 
48  namespace math
49  {
52 
55  class Angle
56  {
58  public: static const Angle Zero;
59 
61  public: static const Angle Pi;
62 
64  public: static const Angle HalfPi;
65 
67  public: static const Angle TwoPi;
68 
70  public: Angle();
71 
74  public: Angle(double _radian);
75 
78  public: Angle(const Angle &_angle);
79 
81  public: virtual ~Angle();
82 
85  public: void SetFromRadian(double _radian);
86 
89  public: void SetFromDegree(double _degree);
90 
93  public: double Radian() const;
94 
97  public: double Degree() const;
98 
100  public: void Normalize();
101 
104  public: inline double operator*() const { return value; }
108  public: Angle operator-(const Angle &_angle) const;
109 
113  public: Angle operator+(const Angle &_angle) const;
114 
118  public: Angle operator*(const Angle &_angle) const;
119 
123  public: Angle operator/(const Angle &_angle) const;
124 
128  public: Angle operator-=(const Angle &_angle);
129 
133  public: Angle operator+=(const Angle &_angle);
134 
138  public: Angle operator*=(const Angle &_angle);
139 
143  public: Angle operator/=(const Angle &_angle);
144 
148  public: bool operator ==(const Angle &_angle) const;
149 
153  public: bool operator!=(const Angle &_angle) const;
154 
158  public: bool operator<(const Angle &_angle) const;
159 
163  public: bool operator<=(const Angle &_angle) const;
164 
168  public: bool operator>(const Angle &_angle) const;
169 
173  public: bool operator>=(const Angle &_angle) const;
174 
179  public: friend std::ostream &operator<<(std::ostream &_out,
180  const gazebo::math::Angle &_a)
181  {
182  _out << _a.Radian();
183  return _out;
184  }
185 
190  public: friend std::istream &operator>>(std::istream &_in,
192  {
193  // Skip white spaces
194  _in.setf(std::ios_base::skipws);
195  _in >> _a.value;
196  return _in;
197  }
198 
200  private: double value;
201  };
202 
204  }
205 }
206 
207 #endif
208 
209 
210