Ignition Math

API Reference

5.1.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 
27 #define IGN_RTOD(r) ((r) * 180 / IGN_PI)
28 
32 #define IGN_DTOR(d) ((d) * IGN_PI / 180)
33 
37 #define IGN_NORMALIZE(a) (atan2(sin(a), cos(a)))
38 
39 namespace ignition
40 {
41  namespace math
42  {
43  // Inline bracket to help doxygen filtering.
44  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
45  //
48  class IGNITION_MATH_VISIBLE Angle
49  {
51  public: static const Angle Zero;
52 
54  public: static const Angle Pi;
55 
57  public: static const Angle HalfPi;
58 
60  public: static const Angle TwoPi;
61 
63  public: Angle();
64 
67  // cppcheck-suppress noExplicitConstructor
68  public: Angle(const double _radian);
69 
72  public: Angle(const Angle &_angle);
73 
75  public: virtual ~Angle();
76 
79  public: void Radian(double _radian);
80 
83  public: void Degree(double _degree);
84 
87  public: double Radian() const;
88 
91  public: double Degree() const;
92 
94  public: void Normalize();
95 
98  public: double operator()() const;
99 
102  public: inline double operator*() const
103  {
104  return value;
105  }
106 
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 
150  public: bool operator==(const Angle &_angle) const;
151 
155  public: bool operator!=(const Angle &_angle) const;
156 
160  public: bool operator<(const Angle &_angle) const;
161 
165  public: bool operator<=(const Angle &_angle) const;
166 
170  public: bool operator>(const Angle &_angle) const;
171 
175  public: bool operator>=(const Angle &_angle) const;
176 
181  public: friend std::ostream &operator<<(std::ostream &_out,
182  const ignition::math::Angle &_a)
183  {
184  _out << _a.Radian();
185  return _out;
186  }
187 
192  public: friend std::istream &operator>>(std::istream &_in,
194  {
195  // Skip white spaces
196  _in.setf(std::ios_base::skipws);
197  _in >> _a.value;
198  return _in;
199  }
200 
202  private: double value;
203  };
204  }
205  }
206 }
207 
208 #endif
An angle and related functions.
Definition: Angle.hh:48
T setf(T... args)
static const Angle Pi
math::Angle(IGN_PI)
Definition: Angle.hh:54
static const Angle HalfPi
math::Angle(IGN_PI * 0.5)
Definition: Angle.hh:57
void Radian(double _radian)
Set the value from an angle in radians.
static const Angle TwoPi
math::Angle(IGN_PI * 2)
Definition: Angle.hh:60
STL class.
friend std::ostream & operator<<(std::ostream &_out, const Angle &_a)
Stream insertion operator. Outputs in degrees.
Definition: Angle.hh:181
friend std::istream & operator>>(std::istream &_in, Angle &_a)
Stream extraction operator. Assumes input is in radians.
Definition: Angle.hh:192
static const Angle Zero
math::Angle(0)
Definition: Angle.hh:51
double operator*() const
Dereference operator.
Definition: Angle.hh:102
Definition: Angle.hh:39
STL class.