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 2011 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 
54  class Angle
55  {
57  public: Angle();
58 
61  public: Angle(double _radian);
62 
65  public: Angle(const Angle &_angle);
66 
68  public: virtual ~Angle();
69 
72  public: void SetFromRadian(double _radian);
73 
76  public: void SetFromDegree(double _degree);
77 
80  public: double GetAsRadian() const __attribute__((deprecated));
81 
84  public: double Radian() const;
85 
88  public: double GetAsDegree() const __attribute__((deprecated));
89 
92  public: double Degree() const;
93 
95  public: void Normalize();
96 
99  public: inline double operator*() const { return value; }
103  public: Angle operator-(const Angle &_angle) const;
104 
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);
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: bool operator ==(const Angle &_angle) const;
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 
174  public: friend std::ostream &operator<<(std::ostream &_out,
175  const gazebo::math::Angle &_a)
176  {
177  _out << _a.Radian();
178  return _out;
179  }
180 
185  public: friend std::istream &operator>>(std::istream &_in,
187  {
188  // Skip white spaces
189  _in.setf(std::ios_base::skipws);
190  _in >> _a.value;
191  return _in;
192  }
193 
195  private: double value;
196  };
197 
199  }
200 }
201 
202 #endif
203 
204 
205