This tutorial explains how to use the Angle
class from Gazebo Math library.
C++ example
Compile the code
Go to gz-math/examples
and use cmake
to compile the code:
When the code is compiled, run:
The ouput of the program:
Code
The code instantiates an angle class. The default constructed angle should be zero.
There are some predefined angles, such as:
By default, all values are in radians, but you can use the method Degree
to convert to degrees.
The Angle
class overloads the +=
, and many other, math operators.
Use the method Normalized
to bound the value between -PI
and PI
.
Ruby example
This example will only work if the Ruby interface library was compiled and installed. For example, on Ubuntu:
Modify the RUBYLIB
environment variable to include the Gazebo Math library install path. For example, if you install to /usr
:
Move to the examples folder:
Execute the code:
Code
There are some predefined values:
Create new objects:
Use the values in radians or degrees:
The Angle
class overloads math operators.
Normalize the value between -PI
and PI
.