Ignition Math

API Reference

6.4.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  //
51  class IGNITION_MATH_VISIBLE Angle
52  {
54  public: static const Angle Zero;
55 
57  public: static const Angle Pi;
58 
60  public: static const Angle HalfPi;
61 
63  public: static const Angle TwoPi;
64 
66  public: Angle();
67 
70  // cppcheck-suppress noExplicitConstructor
71  public: Angle(const double _radian);
72 
75  public: Angle(const Angle &_angle);
76 
78  public: virtual ~Angle();
79 
82  public: void Radian(double _radian);
83 
86  public: void Degree(double _degree);
87 
90  public: double Radian() const;
91 
94  public: double Degree() const;
95 
97  public: void Normalize();
98 
101  public: double operator()() const;
102 
105  public: inline double operator*() const
106  {
107  return value;
108  }
109 
113  public: Angle operator-(const Angle &_angle) const;
114 
118  public: Angle operator+(const Angle &_angle) const;
119 
123  public: Angle operator*(const Angle &_angle) const;
124 
128  public: Angle operator/(const Angle &_angle) const;
129 
133  public: Angle operator-=(const Angle &_angle);
134 
138  public: Angle operator+=(const Angle &_angle);
139 
143  public: Angle operator*=(const Angle &_angle);
144 
148  public: Angle operator/=(const Angle &_angle);
149 
153  public: bool operator==(const Angle &_angle) const;
154 
158  public: bool operator!=(const Angle &_angle) const;
159 
163  public: bool operator<(const Angle &_angle) const;
164 
168  public: bool operator<=(const Angle &_angle) const;
169 
173  public: bool operator>(const Angle &_angle) const;
174 
178  public: bool operator>=(const Angle &_angle) const;
179 
184  public: friend std::ostream &operator<<(std::ostream &_out,
185  const ignition::math::Angle &_a)
186  {
187  _out << _a.Radian();
188  return _out;
189  }
190 
195  public: friend std::istream &operator>>(std::istream &_in,
197  {
198  // Skip white spaces
199  _in.setf(std::ios_base::skipws);
200  _in >> _a.value;
201  return _in;
202  }
203 
205  private: double value;
206  };
207  }
208  }
209 }
210 
211 #endif
An angle and related functions.
Definition: Angle.hh:51
T setf(T... args)
static const Angle Pi
math::Angle(IGN_PI)
Definition: Angle.hh:57
static const Angle HalfPi
math::Angle(IGN_PI * 0.5)
Definition: Angle.hh:60
void Radian(double _radian)
Set the value from an angle in radians.
static const Angle TwoPi
math::Angle(IGN_PI * 2)
Definition: Angle.hh:63
STL class.
friend std::ostream & operator<<(std::ostream &_out, const Angle &_a)
Stream insertion operator. Outputs in degrees.
Definition: Angle.hh:184
friend std::istream & operator>>(std::istream &_in, Angle &_a)
Stream extraction operator. Assumes input is in radians.
Definition: Angle.hh:195
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:54
double operator*() const
Dereference operator.
Definition: Angle.hh:105
Definition: Angle.hh:42
STL class.