Ignition Math

API Reference

6.10.0
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 IGNITION_MATH_ANGLE_HH_
18 #define IGNITION_MATH_ANGLE_HH_
19 
20 #include <iostream>
21 #include <ignition/math/Helpers.hh>
22 #include <ignition/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 ignition::math::Angle &_a)
238  {
239  _out << _a.Radian();
240  return _out;
241  }
242 
247  public: friend std::istream &operator>>(std::istream &_in,
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
The Angle class is used to simplify and clarify the use of radians and degrees measurements. A default constructed Angle instance has a value of zero radians/degrees.
Definition: Angle.hh:61
T setf(T... args)
static const Angle Pi
An angle with a value of Pi. Equivalent to math::Angle(IGN_PI).
Definition: 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: Angle.hh:73
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: Angle.hh:77
STL class.
friend std::ostream & operator<<(std::ostream &_out, const Angle &_a)
Stream insertion operator. Outputs in radians.
Definition: Angle.hh:236
friend std::istream & operator>>(std::istream &_in, Angle &_a)
Stream extraction operator. Assumes input is in radians.
Definition: Angle.hh:247
static const Angle Zero
An angle with a value of zero. Equivalent to math::Angle(0).
Definition: Angle.hh:65
double operator*() const
Dereference operator.
Definition: Angle.hh:157
Definition: Angle.hh:42
STL class.