Gazebo Math

API Reference

8.0.0~pre1
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::math
44{
45 // Inline bracket to help doxygen filtering.
46 inline namespace GZ_MATH_VERSION_NAMESPACE {
47 //
61 {
64 public: static const Angle &Zero;
65
68 public: static const Angle &Pi;
69
72 public: static const Angle &HalfPi;
73
76 public: static const Angle &TwoPi;
77
80 public: Angle() = default;
81
89 //
91 // cppcheck-suppress noExplicitConstructor
92 public: constexpr Angle(double _radian)
93 : value(_radian)
94 {
95 }
96
99 public: void SetRadian(double _radian);
100
103 public: void SetDegree(double _degree);
104
107 public: double Radian() const;
108
111 public: double Degree() const;
112
116 public: void Normalize();
117
121 public: Angle Normalized() const;
122
125 public: Angle Abs() const;
126
130 public: Angle ShortestDistance(const Angle &_other) const;
131
134 public: double operator()() const;
135
138 public: inline double operator*() const
139 {
140 return value;
141 }
142
145 public: Angle operator-() const;
146
150 public: Angle operator-(const Angle &_angle) const;
151
155 public: Angle operator+(const Angle &_angle) const;
156
160 public: Angle operator*(const Angle &_angle) const;
161
165 public: Angle operator/(const Angle &_angle) const;
166
170 public: Angle operator-=(const Angle &_angle);
171
175 public: Angle operator+=(const Angle &_angle);
176
180 public: Angle operator*=(const Angle &_angle);
181
185 public: Angle operator/=(const Angle &_angle);
186
190 public: bool operator==(const Angle &_angle) const;
191
195 public: bool operator!=(const Angle &_angle) const;
196
200 public: bool operator<(const Angle &_angle) const;
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
222 const gz::math::Angle &_a)
223 {
224 _out << _a.Radian();
225 return _out;
226 }
227
234 {
235 // Skip white spaces
236 _in.setf(std::ios_base::skipws);
237 _in >> _a.value;
238 return _in;
239 }
240
242 private: double value{0};
243 };
244 } // namespace GZ_MATH_VERSION_NAMESPACE
245} // namespace gz::math
246
247#endif // GZ_MATH_ANGLE_HH_