Gazebo Math

API Reference

8.0.0

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. More...

#include <gz/math/Angle.hh>

Public Member Functions

 Angle ()=default
 Default constructor that initializes an Angle to zero radians/degrees.
 
constexpr Angle (double _radian)
 Conversion constructor that initializes an Angle to the specified radians. This constructor supports implicit conversion of a double to an Angle. For example:
 
Angle Abs () const
 Return the absolute value of this Angle.
 
double Degree () const
 Get the angle in degrees.
 
void Normalize ()
 Normalize the angle in the range -Pi to Pi. This modifies the value contained in this Angle instance.
 
Angle Normalized () const
 Return the normalized angle in the range -Pi to Pi. This does not modify the value contained in this Angle instance.
 
bool operator!= (const Angle &_angle) const
 Inequality operator.
 
double operator() () const
 Return the angle's radian value.
 
double operator* () const
 Dereference operator.
 
Angle operator* (const Angle &_angle) const
 Multiplication operator, result = this * _angle.
 
Angle operator*= (const Angle &_angle)
 Multiplication set operator, this = this * _angle.
 
Angle operator+ (const Angle &_angle) const
 Addition operator, result = this + _angle.
 
Angle operator+= (const Angle &_angle)
 Addition set operator, this = this + _angle.
 
Angle operator- () const
 Negation operator, result = -this.
 
Angle operator- (const Angle &_angle) const
 Subtraction operator, result = this - _angle.
 
Angle operator-= (const Angle &_angle)
 Subtraction set operator, this = this - _angle.
 
Angle operator/ (const Angle &_angle) const
 Division operator, result = this / _angle.
 
Angle operator/= (const Angle &_angle)
 Division set operator, this = this / _angle.
 
bool operator< (const Angle &_angle) const
 Less than operator.
 
bool operator<= (const Angle &_angle) const
 Less than or equal operator.
 
bool operator== (const Angle &_angle) const
 Equality operator, result = this == _angle.
 
bool operator> (const Angle &_angle) const
 Greater than operator.
 
bool operator>= (const Angle &_angle) const
 Greater than or equal operator.
 
double Radian () const
 Get the angle in radians.
 
void SetDegree (double _degree)
 Set the value from an angle in degrees.
 
void SetRadian (double _radian)
 Set the value from an angle in radians.
 
Angle ShortestDistance (const Angle &_other) const
 Return the shortest angular distance between this and the other angle.
 

Static Public Attributes

static const AngleHalfPi
 An angle with a value of Pi * 0.5. Equivalent to math::Angle(GZ_PI * 0.5).
 
static const AnglePi
 An angle with a value of Pi. Equivalent to math::Angle(GZ_PI).
 
static const AngleTwoPi
 An angle with a value of Pi * 2. Equivalent to math::Angle(GZ_PI * 2).
 
static const AngleZero
 An angle with a value of zero. Equivalent to math::Angle(0).
 

Detailed Description

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.

Unless otherwise specified, the Angle class assumes units are in radians. An example of this are the stream insertion (<<) and extraction (>>) operators.

Example

#include <iostream>
#include <gz/math/Angle.hh>
int main(int argc, char **argv)
{
// A default constructed angle should be zero.
std::cout << "The angle 'a' should be zero: " << a << std::endl;
std::cout << "Pi in radians: " << a << std::endl;
std::cout << "Pi in degrees: " << a.Degree() << std::endl;
std::cout << "Pi + PI/2 in radians: " << a << std::endl;
std::cout << "Normalized to the range -Pi and Pi: "
<< a.Normalized() << std::endl;
}

Constructor & Destructor Documentation

◆ Angle() [1/2]

Angle ( )
default

Default constructor that initializes an Angle to zero radians/degrees.

◆ Angle() [2/2]

constexpr Angle ( double  _radian)
inlineconstexpr

Conversion constructor that initializes an Angle to the specified radians. This constructor supports implicit conversion of a double to an Angle. For example:

Angle a = 3.14;
Parameters
[in]_radianThe radians used to initialize this Angle.

Member Function Documentation

◆ Abs()

Angle Abs ( ) const

Return the absolute value of this Angle.

Returns
The absolute value of this Angle.

◆ Degree()

double Degree ( ) const

Get the angle in degrees.

Returns
Double containing the angle's degree value.

◆ Normalize()

void Normalize ( )

Normalize the angle in the range -Pi to Pi. This modifies the value contained in this Angle instance.

See also
Normalized()

◆ Normalized()

Angle Normalized ( ) const

Return the normalized angle in the range -Pi to Pi. This does not modify the value contained in this Angle instance.

Returns
The normalized value of this Angle.

◆ operator!=()

bool operator!= ( const Angle _angle) const

Inequality operator.

Parameters
[in]_angleAngle to check for inequality.
Returns
True if this != _angle.

◆ operator()()

double operator() ( ) const

Return the angle's radian value.

Returns
double containing the angle's radian value

◆ operator*() [1/2]

double operator* ( ) const
inline

Dereference operator.

Returns
Double containing the angle's radian value

◆ operator*() [2/2]

Angle operator* ( const Angle _angle) const

Multiplication operator, result = this * _angle.

Parameters
[in]_angleAngle for multiplication.
Returns
The new angle

◆ operator*=()

Angle operator*= ( const Angle _angle)

Multiplication set operator, this = this * _angle.

Parameters
[in]_angleAngle for multiplication.
Returns
The new angle.

◆ operator+()

Angle operator+ ( const Angle _angle) const

Addition operator, result = this + _angle.

Parameters
[in]_angleAngle for addition.
Returns
The new angle.

◆ operator+=()

Angle operator+= ( const Angle _angle)

Addition set operator, this = this + _angle.

Parameters
[in]_angleAngle for addition.
Returns
The new angle.

◆ operator-() [1/2]

Angle operator- ( ) const

Negation operator, result = -this.

Returns
The new angle.

◆ operator-() [2/2]

Angle operator- ( const Angle _angle) const

Subtraction operator, result = this - _angle.

Parameters
[in]_angleAngle for subtraction.
Returns
The new angle.

◆ operator-=()

Angle operator-= ( const Angle _angle)

Subtraction set operator, this = this - _angle.

Parameters
[in]_angleAngle for subtraction.
Returns
The new angle.

◆ operator/()

Angle operator/ ( const Angle _angle) const

Division operator, result = this / _angle.

Parameters
[in]_angleAngle for division.
Returns
The new angle.

◆ operator/=()

Angle operator/= ( const Angle _angle)

Division set operator, this = this / _angle.

Parameters
[in]_angleAngle for division.
Returns
The new angle.

◆ operator<()

bool operator< ( const Angle _angle) const

Less than operator.

Parameters
[in]_angleAngle to check.
Returns
True if this < _angle.

◆ operator<=()

bool operator<= ( const Angle _angle) const

Less than or equal operator.

Parameters
[in]_angleAngle to check.
Returns
True if this <= _angle.

◆ operator==()

bool operator== ( const Angle _angle) const

Equality operator, result = this == _angle.

Parameters
[in]_angleAngle to check for equality.
Returns
True if this == _angle.

◆ operator>()

bool operator> ( const Angle _angle) const

Greater than operator.

Parameters
[in]_angleAngle to check.
Returns
True if this > _angle.

◆ operator>=()

bool operator>= ( const Angle _angle) const

Greater than or equal operator.

Parameters
[in]_angleAngle to check.
Returns
True if this >= _angle.

◆ Radian()

double Radian ( ) const

Get the angle in radians.

Returns
Double containing the angle's radian value.

◆ SetDegree()

void SetDegree ( double  _degree)

Set the value from an angle in degrees.

Parameters
[in]_degreeDegree value

◆ SetRadian()

void SetRadian ( double  _radian)

Set the value from an angle in radians.

Parameters
[in]_radianRadian value.

◆ ShortestDistance()

Angle ShortestDistance ( const Angle _other) const

Return the shortest angular distance between this and the other angle.

Returns
The shortest distance.

Member Data Documentation

◆ HalfPi

const Angle& HalfPi
static

An angle with a value of Pi * 0.5. Equivalent to math::Angle(GZ_PI * 0.5).

◆ Pi

const Angle& Pi
static

An angle with a value of Pi. Equivalent to math::Angle(GZ_PI).

◆ TwoPi

const Angle& TwoPi
static

An angle with a value of Pi * 2. Equivalent to math::Angle(GZ_PI * 2).

◆ Zero

const Angle& Zero
static

An angle with a value of zero. Equivalent to math::Angle(0).


The documentation for this class was generated from the following file: