Angle.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 #ifndef GAZEBO_MATH_ANGLE_HH_
18 #define GAZEBO_MATH_ANGLE_HH_
19 
20 #include <math.h>
21 #include <ignition/math/Angle.hh>
22 #include <iostream>
23 #include "gazebo/util/system.hh"
24 
28 #define GZ_RTOD(r) gazebo::math::Angle::RadiansToDegrees(r)
29 
33 #define GZ_DTOR(d) gazebo::math::Angle::DegreesToRadians(d)
34 
38 #define GZ_NORMALIZE(a) gazebo::math::Angle::Normalize(a)
39 
40 namespace gazebo
41 {
43 
45  namespace math
46  {
49 
52  // cppcheck-suppress noConstructor
53  class GZ_MATH_VISIBLE Angle
54  {
56  public: static const Angle Zero;
57 
59  public: static const Angle Pi;
60 
62  public: static const Angle HalfPi;
63 
65  public: static const Angle TwoPi;
66 
68  public: Angle() GAZEBO_DEPRECATED(8.0);
69 
72  public: Angle(double _radian) GAZEBO_DEPRECATED(8.0);
73 
76  public: Angle(const Angle &_angle) GAZEBO_DEPRECATED(8.0);
77 
80  public: Angle(const ignition::math::Angle &_angle) GAZEBO_DEPRECATED(8.0);
81 
83  public: virtual ~Angle();
84 
87  public: void SetFromRadian(double _radian);
88 
91  public: void SetFromDegree(double _degree);
92 
95  public: double Radian() const;
96 
99  public: double Degree() const;
100 
102  public: void Normalize();
103 
106  public: inline double operator*() const { return value; }
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) const;
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: Angle operator/=(const Angle &_angle);
146 
149  public: ignition::math::Angle Ign() const;
150 
154  public: Angle &operator=(const double &_angle);
155 
159  public: Angle &operator=(const ignition::math::Angle &_angle);
160 
164  public: bool operator ==(const Angle &_angle) const;
165 
169  public: bool operator!=(const Angle &_angle) const;
170 
174  public: bool operator<(const Angle &_angle) const;
175 
179  public: bool operator<=(const Angle &_angle) const;
180 
184  public: bool operator>(const Angle &_angle) const;
185 
189  public: bool operator>=(const Angle &_angle) const;
190 
195  public: friend std::ostream &operator<<(std::ostream &_out,
196  const gazebo::math::Angle &_a)
197  {
198  _out << _a.Radian();
199  return _out;
200  }
201 
205  public: static double DegreesToRadians(const double _d)
206  GAZEBO_DEPRECATED(8.0)
207  {
208  return _d * M_PI / 180;
209  }
210 
214  public: static double RadiansToDegrees(const double _r)
215  GAZEBO_DEPRECATED(8.0)
216  {
217  return _r * 180 / M_PI;
218  }
219 
223  public: static double Normalize(const double _a)
224  GAZEBO_DEPRECATED(8.0)
225  {
226  return atan2(sin(_a), cos(_a));
227  }
228 
233  public: friend std::istream &operator>>(std::istream &_in,
235  {
236  // Skip white spaces
237  _in.setf(std::ios_base::skipws);
238  _in >> _a.value;
239  return _in;
240  }
241 
243  private: double value;
244  };
245 
247  }
248 }
249 
250 #endif
251 
252 
253 
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Angle &_a)
Stream insertion operator.
Definition: Angle.hh:195
static const Angle HalfPi
math::Angle(M_PI * 0.5)
Definition: Angle.hh:62
static double DegreesToRadians(const double _d) GAZEBO_DEPRECATED(8.0)
Converts degrees to radians.
Definition: Angle.hh:205
friend std::istream & operator>>(std::istream &_in, gazebo::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:233
static const double GAZEBO_DEPRECATED(8.0) MAX_D
Double maximum value. This value will be similar to 1.79769e+308.
Definition: Helpers.hh:140
static const Angle TwoPi
math::Angle(M_PI * 2)
Definition: Angle.hh:65
double Radian() const
Get the angle in radians.
static const Angle Pi
math::Angle(M_PI)
Definition: Angle.hh:59
static double Normalize(const double _a) GAZEBO_DEPRECATED(8.0)
Macro that normalizes an angle in the range -Pi to Pi.
Definition: Angle.hh:223
static double RadiansToDegrees(const double _r) GAZEBO_DEPRECATED(8.0)
Converts radians to degrees.
Definition: Angle.hh:214
An angle and related functions.
Definition: Angle.hh:53
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:56