Angle.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 
18 #ifndef _ANGLE_HH_
19 #define _ANGLE_HH_
20 
21 #include <math.h>
22 #include <iostream>
23 #include "gazebo/util/system.hh"
24 
28 #define GZ_RTOD(r) ((r) * 180 / M_PI)
29 
33 #define GZ_DTOR(d) ((d) * M_PI / 180)
34 
38 #define GZ_NORMALIZE(a) (atan2(sin(a), cos(a)))
39 
40 namespace gazebo
41 {
43 
45  namespace math
46  {
49 
53  {
55  public: static const Angle Zero;
56 
58  public: static const Angle Pi;
59 
61  public: static const Angle HalfPi;
62 
64  public: static const Angle TwoPi;
65 
67  public: Angle();
68 
71  public: Angle(double _radian);
72 
75  public: Angle(const Angle &_angle);
76 
78  public: virtual ~Angle();
79 
82  public: void SetFromRadian(double _radian);
83 
86  public: void SetFromDegree(double _degree);
87 
90  public: double Radian() const;
91 
94  public: double Degree() const;
95 
97  public: void Normalize();
98 
101  public: inline double operator*() const { return value; }
105  public: Angle operator-(const Angle &_angle) const;
106 
110  public: Angle operator+(const Angle &_angle) const;
111 
115  public: Angle operator*(const Angle &_angle) const;
116 
120  public: Angle operator/(const Angle &_angle) const;
121 
125  public: Angle operator-=(const Angle &_angle);
126 
130  public: Angle operator+=(const Angle &_angle);
131 
135  public: Angle operator*=(const Angle &_angle);
136 
140  public: Angle operator/=(const Angle &_angle);
141 
145  public: bool operator ==(const Angle &_angle) const;
146 
150  public: bool operator!=(const Angle &_angle) const;
151 
155  public: bool operator<(const Angle &_angle) const;
156 
160  public: bool operator<=(const Angle &_angle) const;
161 
165  public: bool operator>(const Angle &_angle) const;
166 
170  public: bool operator>=(const Angle &_angle) const;
171 
176  public: friend std::ostream &operator<<(std::ostream &_out,
177  const gazebo::math::Angle &_a)
178  {
179  _out << _a.Radian();
180  return _out;
181  }
182 
187  public: friend std::istream &operator>>(std::istream &_in,
189  {
190  // Skip white spaces
191  _in.setf(std::ios_base::skipws);
192  _in >> _a.value;
193  return _in;
194  }
195 
197  private: double value;
198  };
199 
201  }
202 }
203 
204 #endif
205 
206 
207 
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Angle &_a)
Stream insertion operator.
Definition: Angle.hh:176
static const Angle Pi
math::Angle(M_PI)
Definition: Angle.hh:58
friend std::istream & operator>>(std::istream &_in, gazebo::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:187
double operator*() const
Dereference operator.
Definition: Angle.hh:101
static const Angle TwoPi
math::Angle(M_PI * 2)
Definition: Angle.hh:64
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:55
double Radian() const
Get the angle in radians.
static const Angle HalfPi
math::Angle(M_PI * 0.5)
Definition: Angle.hh:61
An angle and related functions.
Definition: Angle.hh:52
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48