Apollo  6.0
Open source self driving car software
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
apollo::common::math::Angle< T > Class Template Reference

The Angle class uses an integer to represent an angle, and supports commonly-used operations such as addition and subtraction, as well as the use of trigonometric functions. More...

#include <angle.h>

Collaboration diagram for apollo::common::math::Angle< T >:
Collaboration graph

Public Member Functions

 Angle (const T value=0)
 Constructs an Angle object from raw internal value. More...
 
raw () const
 Getter of value_. More...
 
double to_deg () const
 Converts the internal representation to degrees. More...
 
double to_rad () const
 Converts the internal representation to radians. More...
 
Angle operator+= (Angle other)
 Sums another angle to the current one. More...
 
Angle operator-= (Angle other)
 Subtracts another angle from the current one. More...
 
template<typename Scalar >
Angle operator*= (Scalar s)
 Multiplies angle by scalar. More...
 
template<typename Scalar >
Angle operator/= (Scalar s)
 Divides angle by scalar. More...
 

Static Public Member Functions

static Angle from_deg (const double value)
 Constructs an Angle object from an angle in degrees (factory). More...
 
static Angle from_rad (const double value)
 Constructs an Angle object from an angle in radians (factory). More...
 

Static Public Attributes

static constexpr T RAW_PI = std::numeric_limits<T>::min()
 Internal representation of pi. More...
 
static constexpr T RAW_PI_2
 Internal representation of pi/2. More...
 
static constexpr double DEG_TO_RAW = RAW_PI / -180.0
 Used for converting angle units. More...
 
static constexpr double RAD_TO_RAW = RAW_PI * -M_1_PI
 Used for converting angle units. More...
 
static constexpr double RAW_TO_DEG = -180.0 / RAW_PI
 Used for converting angle units. More...
 
static constexpr double RAW_TO_RAD = -M_PI / RAW_PI
 Used for converting angle units. More...
 

Detailed Description

template<typename T>
class apollo::common::math::Angle< T >

The Angle class uses an integer to represent an angle, and supports commonly-used operations such as addition and subtraction, as well as the use of trigonometric functions.

Having a specialized Angle class prevents code repetition, namely for tasks such as computing angle differences or finding equivalent angles in some specified interval, typically [-pi, pi). Representing angles by integers has the following advantages: 1) Finer level of precision control (< means "less precise than"): Angle8 < Angle16 < float < Angle32 < double < Angle64. 2) Angle8 and Angle16 allow super fast trigonometric functions via a 64-KiB lookup table. 3) Higher precision with the same representation size. The use of the Angle class is encouraged. In particular, Angle32 should be used for latitude/longitude (<1cm error). Angle16 is precise enough for localization/object detection.

Parameters
Tsigned integer type

Constructor & Destructor Documentation

◆ Angle()

template<typename T>
apollo::common::math::Angle< T >::Angle ( const T  value = 0)
inlineexplicit

Constructs an Angle object from raw internal value.

Parameters
valueAngle in degrees
Returns
Angle object

Member Function Documentation

◆ from_deg()

template<typename T>
static Angle apollo::common::math::Angle< T >::from_deg ( const double  value)
inlinestatic

Constructs an Angle object from an angle in degrees (factory).

Parameters
valueAngle in degrees
Returns
Angle object

◆ from_rad()

template<typename T>
static Angle apollo::common::math::Angle< T >::from_rad ( const double  value)
inlinestatic

Constructs an Angle object from an angle in radians (factory).

Parameters
valueAngle in radians
Returns
Angle object

◆ operator*=()

template<typename T>
template<typename Scalar >
Angle apollo::common::math::Angle< T >::operator*= ( Scalar  s)
inline

Multiplies angle by scalar.

Parameters
sA scalar
Returns
Result of multiplication

◆ operator+=()

template<typename T>
Angle apollo::common::math::Angle< T >::operator+= ( Angle< T >  other)
inline

Sums another angle to the current one.

Parameters
otherAnother Angle object
Returns
Result of sum

◆ operator-=()

template<typename T>
Angle apollo::common::math::Angle< T >::operator-= ( Angle< T >  other)
inline

Subtracts another angle from the current one.

Parameters
otherAnother Angle object
Returns
Result of subtraction

◆ operator/=()

template<typename T>
template<typename Scalar >
Angle apollo::common::math::Angle< T >::operator/= ( Scalar  s)
inline

Divides angle by scalar.

Parameters
sA scalar
Returns
Result of division

◆ raw()

template<typename T>
T apollo::common::math::Angle< T >::raw ( ) const
inline

Getter of value_.

Returns
Internal unsigned integer representation of angle

◆ to_deg()

template<typename T>
double apollo::common::math::Angle< T >::to_deg ( ) const
inline

Converts the internal representation to degrees.

Returns
angle in degrees

◆ to_rad()

template<typename T>
double apollo::common::math::Angle< T >::to_rad ( ) const
inline

Converts the internal representation to radians.

Returns
angle in radians

Member Data Documentation

◆ DEG_TO_RAW

template<typename T>
constexpr double apollo::common::math::Angle< T >::DEG_TO_RAW = RAW_PI / -180.0
static

Used for converting angle units.

◆ RAD_TO_RAW

template<typename T>
constexpr double apollo::common::math::Angle< T >::RAD_TO_RAW = RAW_PI * -M_1_PI
static

Used for converting angle units.

◆ RAW_PI

template<typename T>
constexpr T apollo::common::math::Angle< T >::RAW_PI = std::numeric_limits<T>::min()
static

Internal representation of pi.

◆ RAW_PI_2

template<typename T>
constexpr T apollo::common::math::Angle< T >::RAW_PI_2
static
Initial value:
=
static_cast<T>(-(std::numeric_limits<T>::min() >> 1))

Internal representation of pi/2.

◆ RAW_TO_DEG

template<typename T>
constexpr double apollo::common::math::Angle< T >::RAW_TO_DEG = -180.0 / RAW_PI
static

Used for converting angle units.

◆ RAW_TO_RAD

template<typename T>
constexpr double apollo::common::math::Angle< T >::RAW_TO_RAD = -M_PI / RAW_PI
static

Used for converting angle units.


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