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  //
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 
101  public: virtual ~Angle();
102 
106  public: void Radian(double _radian);
107 
110  public: void SetRadian(double _radian);
111 
115  public: void Degree(double _degree);
116 
119  public: void SetDegree(double _degree);
120 
123  public: double Radian() const;
124 
127  public: double Degree() const;
128 
132  public: void Normalize();
133 
137  public: Angle Normalized() const;
138 
141  public: double operator()() const;
142 
145  public: inline double operator*() const
146  {
147  return value;
148  }
149 
153  public: Angle operator-(const Angle &_angle) const;
154 
158  public: Angle operator+(const Angle &_angle) const;
159 
163  public: Angle operator*(const Angle &_angle) const;
164 
168  public: Angle operator/(const Angle &_angle) const;
169 
173  public: Angle operator-=(const Angle &_angle);
174 
178  public: Angle operator+=(const Angle &_angle);
179 
183  public: Angle operator*=(const Angle &_angle);
184 
188  public: Angle operator/=(const Angle &_angle);
189 
193  public: bool operator==(const Angle &_angle) const;
194 
198  public: bool operator!=(const Angle &_angle) const;
199 
203  public: bool operator<(const Angle &_angle) const;
204 
208  public: bool operator<=(const Angle &_angle) const;
209 
213  public: bool operator>(const Angle &_angle) const;
214 
218  public: bool operator>=(const Angle &_angle) const;
219 
224  public: friend std::ostream &operator<<(std::ostream &_out,
225  const ignition::math::Angle &_a)
226  {
227  _out << _a.Radian();
228  return _out;
229  }
230 
235  public: friend std::istream &operator>>(std::istream &_in,
237  {
238  // Skip white spaces
239  _in.setf(std::ios_base::skipws);
240  _in >> _a.value;
241  return _in;
242  }
243 
245  private: double value{0};
246  };
247  }
248  }
249 }
250 
251 #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:224
friend std::istream & operator>>(std::istream &_in, Angle &_a)
Stream extraction operator. Assumes input is in radians.
Definition: Angle.hh:235
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:145
Definition: Angle.hh:42
STL class.