Gazebo Math

API Reference

7.4.0
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 <istream>
21#include <ostream>
22#include <gz/math/Helpers.hh>
23#include <gz/math/config.hh>
24
29#define GZ_RTOD(r) ((r) * 180 / GZ_PI)
30
35#define GZ_DTOR(d) ((d) * GZ_PI / 180)
36
41#define GZ_NORMALIZE(a) (atan2(sin(a), cos(a)))
42
43namespace gz
44{
45 namespace math
46 {
47 // Inline bracket to help doxygen filtering.
48 inline namespace GZ_MATH_VERSION_NAMESPACE {
49 //
62 class GZ_MATH_VISIBLE Angle
63 {
66 public: static const Angle &Zero;
67
70 public: static const Angle &Pi;
71
74 public: static const Angle &HalfPi;
75
78 public: static const Angle &TwoPi;
79
82 public: Angle() = default;
83
91 //
93 // cppcheck-suppress noExplicitConstructor
94 public: constexpr Angle(double _radian)
95 : value(_radian)
96 {
97 }
98
102 public: void GZ_DEPRECATED(7) Radian(double _radian);
103
106 public: void SetRadian(double _radian);
107
111 public: void GZ_DEPRECATED(7) Degree(double _degree);
112
115 public: void SetDegree(double _degree);
116
119 public: double Radian() const;
120
123 public: double Degree() const;
124
128 public: void Normalize();
129
133 public: Angle Normalized() const;
134
137 public: double operator()() const;
138
141 public: inline double operator*() const
142 {
143 return value;
144 }
145
149 public: Angle operator-(const Angle &_angle) const;
150
154 public: Angle operator+(const Angle &_angle) const;
155
159 public: Angle operator*(const Angle &_angle) const;
160
164 public: Angle operator/(const Angle &_angle) const;
165
169 public: Angle operator-=(const Angle &_angle);
170
174 public: Angle operator+=(const Angle &_angle);
175
179 public: Angle operator*=(const Angle &_angle);
180
184 public: Angle operator/=(const Angle &_angle);
185
189 public: bool operator==(const Angle &_angle) const;
190
194 public: bool operator!=(const Angle &_angle) const;
195
199 public: bool operator<(const Angle &_angle) const;
200
204 public: bool operator<=(const Angle &_angle) const;
205
209 public: bool operator>(const Angle &_angle) const;
210
214 public: bool operator>=(const Angle &_angle) const;
215
220 public: friend std::ostream &operator<<(std::ostream &_out,
221 const gz::math::Angle &_a)
222 {
223 _out << _a.Radian();
224 return _out;
225 }
226
232 gz::math::Angle &_a)
233 {
234 // Skip white spaces
235 _in.setf(std::ios_base::skipws);
236 _in >> _a.value;
237 return _in;
238 }
239
241 private: double value{0};
242 };
243 }
244 }
245}
246
247#endif