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 _GAZEBO_ANGLE_HH_
19 #define _GAZEBO_ANGLE_HH_
20 
21 #include <math.h>
22 #include <ignition/math/Angle.hh>
23 #include <iostream>
24 #include "gazebo/util/system.hh"
25 
29 #define GZ_RTOD(r) ((r) * 180 / M_PI)
30 
34 #define GZ_DTOR(d) ((d) * M_PI / 180)
35 
39 #define GZ_NORMALIZE(a) (atan2(sin(a), cos(a)))
40 
41 namespace gazebo
42 {
44 
46  namespace math
47  {
50 
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();
69 
72  public: Angle(double _radian);
73 
76  public: Angle(const Angle &_angle);
77 
80  public: Angle(const ignition::math::Angle &_angle);
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 
206  public: friend std::istream &operator>>(std::istream &_in,
208  {
209  // Skip white spaces
210  _in.setf(std::ios_base::skipws);
211  _in >> _a.value;
212  return _in;
213  }
214 
216  private: double value;
217  };
218 
220  }
221 }
222 
223 #endif
224 
225 
226 
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Angle &_a)
Stream insertion operator.
Definition: Angle.hh:195
static const Angle Pi
math::Angle(M_PI)
Definition: Angle.hh:59
friend std::istream & operator>>(std::istream &_in, gazebo::math::Angle &_a)
Stream extraction operator.
Definition: Angle.hh:206
double operator*() const
Dereference operator.
Definition: Angle.hh:106
static const Angle TwoPi
math::Angle(M_PI * 2)
Definition: Angle.hh:65
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:56
double Radian() const
Get the angle in radians.
#define GZ_MATH_VISIBLE
Definition: system.hh:141
static const Angle HalfPi
math::Angle(M_PI * 0.5)
Definition: Angle.hh:62
An angle and related functions.
Definition: Angle.hh:53