Gazebo Math

API Reference

6.15.1
gz/math/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 GZ_MATH_ANGLE_HH_
18 #define GZ_MATH_ANGLE_HH_
19 
20 #include <iostream>
21 #include <gz/math/Helpers.hh>
22 #include <gz/math/config.hh>
23 
28 #define IGN_RTOD(r) ((r) * 180 / IGN_PI)
29 
34 #define IGN_DTOR(d) ((d) * IGN_PI / 180)
35 
40 #define IGN_NORMALIZE(a) (atan2(sin(a), cos(a)))
41 
42 namespace ignition
43 {
44  namespace math
45  {
46  // Inline bracket to help doxygen filtering.
47  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
48  //
61  class IGNITION_MATH_VISIBLE Angle
62  {
65  public: static const Angle Zero;
66 
69  public: static const Angle Pi;
70 
73  public: static const Angle HalfPi;
74 
77  public: static const Angle TwoPi;
78 
81  public: Angle();
82 
90  //
92  // cppcheck-suppress noExplicitConstructor
93  public: Angle(const double _radian);
94 
98  public: Angle(const Angle &_angle);
99 
102  public: Angle(Angle &&_angle) noexcept;
103 
105  public: virtual ~Angle();
106 
109  public: Angle& operator=(const Angle &_angle);
110 
113  public: Angle& operator=(Angle &&_angle) noexcept;
114 
118  public: void Radian(double _radian);
119 
122  public: void SetRadian(double _radian);
123 
127  public: void Degree(double _degree);
128 
131  public: void SetDegree(double _degree);
132 
135  public: double Radian() const;
136 
139  public: double Degree() const;
140 
144  public: void Normalize();
145 
149  public: Angle Normalized() const;
150 
153  public: double operator()() const;
154 
157  public: inline double operator*() const
158  {
159  return value;
160  }
161 
165  public: Angle operator-(const Angle &_angle) const;
166 
170  public: Angle operator+(const Angle &_angle) const;
171 
175  public: Angle operator*(const Angle &_angle) const;
176 
180  public: Angle operator/(const Angle &_angle) const;
181 
185  public: Angle operator-=(const Angle &_angle);
186 
190  public: Angle operator+=(const Angle &_angle);
191 
195  public: Angle operator*=(const Angle &_angle);
196 
200  public: Angle operator/=(const Angle &_angle);
201 
205  public: bool operator==(const Angle &_angle) const;
206 
210  public: bool operator!=(const Angle &_angle) const;
211 
215  public: bool operator<(const Angle &_angle) const;
216 
220  public: bool operator<=(const Angle &_angle) const;
221 
225  public: bool operator>(const Angle &_angle) const;
226 
230  public: bool operator>=(const Angle &_angle) const;
231 
236  public: friend std::ostream &operator<<(std::ostream &_out,
237  const gz::math::Angle &_a)
238  {
239  _out << _a.Radian();
240  return _out;
241  }
242 
247  public: friend std::istream &operator>>(std::istream &_in,
248  gz::math::Angle &_a)
249  {
250  // Skip white spaces
251  _in.setf(std::ios_base::skipws);
252  _in >> _a.value;
253  return _in;
254  }
255 
257  private: double value{0};
258  };
259  }
260  }
261 }
262 
263 #endif
bool operator>=(const Angle &_angle) const
Greater than or equal operator.
Angle operator/=(const Angle &_angle)
Division set operator, this = this / _angle.
Angle operator-(const Angle &_angle) const
Subtraction operator, result = this - _angle.
Angle operator+(const Angle &_angle) const
Addition operator, result = this + _angle.
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
Angle operator*=(const Angle &_angle)
Multiplication set operator, this = this * _angle.
void Radian(double _radian)
Set the value from an angle in radians.
static const Angle TwoPi
An angle with a value of Pi * 2. Equivalent to math::Angle(IGN_PI * 2).
Definition: gz/math/Angle.hh:77
Angle operator/(const Angle &_angle) const
Division operator, result = this / _angle.
virtual ~Angle()
Destructor.
void SetDegree(double _degree)
Set the value from an angle in degrees.
bool operator>(const Angle &_angle) const
Greater than operator.
Angle & operator=(const Angle &_angle)
Copy assignment operator.
Angle Normalized() const
Return the normalized angle in the range -Pi to Pi. This does not modify the value contained in this ...
double operator()() const
Return the angle's radian value.
double Radian() const
Get the angle in radians.
void SetRadian(double _radian)
Set the value from an angle in radians.
friend std::ostream & operator<<(std::ostream &_out, const Angle &_a)
Stream insertion operator. Outputs in radians.
Definition: gz/math/Angle.hh:236
STL class.
bool operator<(const Angle &_angle) const
Less than operator.
friend std::istream & operator>>(std::istream &_in, Angle &_a)
Stream extraction operator. Assumes input is in radians.
Definition: gz/math/Angle.hh:247
T setf(T... args)
double Degree() const
Get the angle in degrees.
bool operator<=(const Angle &_angle) const
Less than or equal operator.
Angle operator-=(const Angle &_angle)
Subtraction set operator, this = this - _angle.
Angle operator+=(const Angle &_angle)
Addition set operator, this = this + _angle.
bool operator!=(const Angle &_angle) const
Inequality operator.
Angle()
Default constructor that initializes an Angle to zero radians/degrees.
void Normalize()
Normalize the angle in the range -Pi to Pi. This modifies the value contained in this Angle instance.
The Angle class is used to simplify and clarify the use of radians and degrees measurements....
Definition: gz/math/Angle.hh:61
bool operator==(const Angle &_angle) const
Equality operator, result = this == _angle.
static const Angle Pi
An angle with a value of Pi. Equivalent to math::Angle(IGN_PI).
Definition: gz/math/Angle.hh:69
static const Angle HalfPi
An angle with a value of Pi * 0.5. Equivalent to math::Angle(IGN_PI * 0.5).
Definition: gz/math/Angle.hh:73
static const Angle Zero
An angle with a value of zero. Equivalent to math::Angle(0).
Definition: gz/math/Angle.hh:65
STL class.
double operator*() const
Dereference operator.
Definition: gz/math/Angle.hh:157