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 Nate Koenig
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 GetAsRadian() const __attribute__((deprecated));
82 
85  public: double Radian() const;
86 
89  public: double GetAsDegree() const __attribute__((deprecated));
90 
93  public: double Degree() const;
94 
96  public: void Normalize();
97 
100  public: inline double operator*() const { return value; }
104  public: Angle operator-(const Angle &_angle) const;
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);
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: bool operator ==(const Angle &_angle) const;
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 
175  public: friend std::ostream &operator<<(std::ostream &_out,
176  const gazebo::math::Angle &_a)
177  {
178  _out << _a.Radian();
179  return _out;
180  }
181 
186  public: friend std::istream &operator>>(std::istream &_in,
188  {
189  // Skip white spaces
190  _in.setf(std::ios_base::skipws);
191  _in >> _a.value;
192  return _in;
193  }
194 
196  private: double value;
197  };
198 
200  }
201 }
202 
203 #endif
204 
205 
206