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: Angle();
59 
62  public: Angle(double _radian);
63 
66  public: Angle(const Angle &_angle);
67 
69  public: virtual ~Angle();
70 
73  public: void SetFromRadian(double _radian);
74 
77  public: void SetFromDegree(double _degree);
78 
81  public: double Radian() const;
82 
85  public: double Degree() const;
86 
88  public: void Normalize();
89 
92  public: inline double operator*() const { return value; }
96  public: Angle operator-(const Angle &_angle) const;
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);
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: bool operator ==(const Angle &_angle) const;
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 
167  public: friend std::ostream &operator<<(std::ostream &_out,
168  const gazebo::math::Angle &_a)
169  {
170  _out << _a.Radian();
171  return _out;
172  }
173 
178  public: friend std::istream &operator>>(std::istream &_in,
180  {
181  // Skip white spaces
182  _in.setf(std::ios_base::skipws);
183  _in >> _a.value;
184  return _in;
185  }
186 
188  private: double value;
189  };
190 
192  }
193 }
194 
195 #endif
196 
197 
198