Drake
TrigPoly< _CoefficientType > Class Template Referencefinal

Detailed Description

template<typename _CoefficientType = double> class TrigPoly< _CoefficientType >

A scalar multi-variate polynomial containing sines and cosines.

TrigPoly represents a Polynomial some of whose variables actually represent the sines or cosines of other variables. Sines and cosines of first-order polynomials (affine combinations of variables) are decomposed into polynomials of the sines and cosines of individual variables via the Prosthaphaeresis formulae.

Any variables which will appear in the arguments to trigonometric functions must be declared in the "SinCosMap" (created automatically by most TrigPoly constructors); attempting to, e.g., use sin(x) without first creating a SinCosMap mapping for 'x' will result in an exception.

The same variable may not appear more than once in the sin_cos_map, regardless of position.

For example:

Polynomial base_x("x"), s("s"), c("c");
TrigPoly x(base_x, s, c) // This "x" knows that s = sin(x)
// and that c = cos(x)
cout << sin(x) // emits "s1"
cout << sin(x) * x // emits "x1*s1"
cout << sin(x + x) * x // emits "x1*s1*c1 + x1*c1*s1"

NOTE: Certain analyses may not succeed when individual Monomials contain both x and sin(x) or cos(x) terms. This restriction is not currently enforced programmatically.

#include <drake/common/trig_poly.h>

Classes

struct  Product

struct  SinCosVars

Public Types

typedef _CoefficientType CoefficientType

typedef Polynomial< CoefficientTypePolyType

typedef PolyType::VarType VarType

Public Member Functions

TrigPoly ()
Constructs a vacuous TrigPoly. More...

TrigPoly (const CoefficientType &scalar)
Constructs a constant TrigPoly. More...

TrigPoly (const PolyType &p)
Constructs a TrigPoly on the associated Polynomial p with no associated trigonometric correspondences. More...

TrigPoly (const PolyType &p, const SinCosMap &_sin_cos_map)
Constructs a TrigPoly on the associated Polynomial p, but with the additional information about sin and cos relations in _sin_cos_map. More...

TrigPoly (const PolyType &q, const PolyType &s, const PolyType &c)
Constructs a TrigPoly version of q, but with the additional information that the variables s and c represent the sine and cosine of q. More...

~TrigPoly ()=default

const PolyTypepoly (void) const
Returns the underlying Polynomial for this TrigPoly. More...

const SinCosMapsin_cos_map (void) const
Returns the SinCosMap for this TrigPoly. More...

std::set< VarTypeGetVariables () const
Returns all of the base (non-sin/cos) variables in this TrigPoly. More...

template<typename T >
Product< CoefficientType, T >::type EvaluateMultivariate (const std::map< VarType, T > &var_values) const
Given a value for every variable in this expression, evaluates it. More...

virtual TrigPoly< CoefficientTypeEvaluatePartial (const std::map< VarType, CoefficientType > &var_values) const
Partially evaluates this expression, returning the resulting expression. More...

bool operator== (const TrigPoly &other) const
Compares two TrigPolys for equality. More...

TrigPolyoperator+= (const TrigPoly &other)

TrigPolyoperator-= (const TrigPoly &other)

TrigPolyoperator *= (const TrigPoly &other)

TrigPolyoperator+= (const CoefficientType &scalar)

TrigPolyoperator-= (const CoefficientType &scalar)

TrigPolyoperator *= (const CoefficientType &scalar)

TrigPolyoperator/= (const CoefficientType &scalar)

const TrigPoly operator+ (const TrigPoly &other) const

const TrigPoly operator- (const TrigPoly &other) const

const TrigPoly operator- () const

const TrigPoly operator * (const TrigPoly &other) const

const TrigPoly operator/ (const CoefficientType &scalar) const

Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
TrigPoly (const TrigPoly &)=default

TrigPolyoperator= (const TrigPoly &)=default

TrigPoly (TrigPoly &&)=default

TrigPolyoperator= (TrigPoly &&)=default

Friends

TrigPoly sin (const TrigPoly &p)
A version of sin that handles TrigPoly arguments through ADL. More...

TrigPoly cos (const TrigPoly &p)
A version of cos that handles TrigPoly arguments through ADL. More...

const TrigPoly operator+ (const TrigPoly &p, const CoefficientType &scalar)

const TrigPoly operator+ (const CoefficientType &scalar, const TrigPoly &p)

const TrigPoly operator- (const TrigPoly &p, const CoefficientType &scalar)

const TrigPoly operator- (const CoefficientType &scalar, const TrigPoly &p)

const TrigPoly operator * (const TrigPoly &p, const CoefficientType &scalar)

const TrigPoly operator * (const CoefficientType &scalar, const TrigPoly &p)

std::ostream & operator<< (std::ostream &os, const TrigPoly< CoefficientType > &tp)

◆ CoefficientType

 typedef _CoefficientType CoefficientType

◆ PolyType

 typedef Polynomial PolyType

◆ SinCosMap

 typedef std::map SinCosMap

◆ VarType

 typedef PolyType::VarType VarType

◆ TrigPoly() [1/7]

 TrigPoly ( const TrigPoly< _CoefficientType > & )
default

◆ TrigPoly() [2/7]

 TrigPoly ( TrigPoly< _CoefficientType > && )
default

◆ TrigPoly() [3/7]

 TrigPoly ( )

Constructs a vacuous TrigPoly.

◆ TrigPoly() [4/7]

 TrigPoly ( const CoefficientType & scalar )

Constructs a constant TrigPoly.

◆ TrigPoly() [5/7]

 TrigPoly ( const PolyType & p )
explicit

Constructs a TrigPoly on the associated Polynomial p with no associated trigonometric correspondences.

◆ TrigPoly() [6/7]

 TrigPoly ( const PolyType & p, const SinCosMap & _sin_cos_map )

Constructs a TrigPoly on the associated Polynomial p, but with the additional information about sin and cos relations in _sin_cos_map.

◆ TrigPoly() [7/7]

 TrigPoly ( const PolyType & q, const PolyType & s, const PolyType & c )

Constructs a TrigPoly version of q, but with the additional information that the variables s and c represent the sine and cosine of q.

◆ ~TrigPoly()

 ~TrigPoly ( )
default

◆ EvaluateMultivariate()

 Product::type EvaluateMultivariate ( const std::map< VarType, T > & var_values ) const

Given a value for every variable in this expression, evaluates it.

By analogy with Polynomial::EvaluateMultivariate(). Values must be supplied for all base variables; supplying values for sin/cos variables is an error.

◆ EvaluatePartial()

 virtual TrigPoly EvaluatePartial ( const std::map< VarType, CoefficientType > & var_values ) const
virtual

Partially evaluates this expression, returning the resulting expression.

By analogy with Polynomial::evaluatePartial. Values must be supplied for all base variables only; supplying values for sin/cos variables is an error.

◆ GetVariables()

 std::set GetVariables ( ) const

Returns all of the base (non-sin/cos) variables in this TrigPoly.

◆ operator *()

 const TrigPoly operator * ( const TrigPoly< _CoefficientType > & other ) const

◆ operator *=() [1/2]

 TrigPoly& operator *= ( const TrigPoly< _CoefficientType > & other )

◆ operator *=() [2/2]

 TrigPoly& operator *= ( const CoefficientType & scalar )

◆ operator+()

 const TrigPoly operator+ ( const TrigPoly< _CoefficientType > & other ) const

◆ operator+=() [1/2]

 TrigPoly& operator+= ( const TrigPoly< _CoefficientType > & other )

◆ operator+=() [2/2]

 TrigPoly& operator+= ( const CoefficientType & scalar )

◆ operator-() [1/2]

 const TrigPoly operator- ( const TrigPoly< _CoefficientType > & other ) const

◆ operator-() [2/2]

 const TrigPoly operator- ( ) const

◆ operator-=() [1/2]

 TrigPoly& operator-= ( const TrigPoly< _CoefficientType > & other )

◆ operator-=() [2/2]

 TrigPoly& operator-= ( const CoefficientType & scalar )

◆ operator/()

 const TrigPoly operator/ ( const CoefficientType & scalar ) const

◆ operator/=()

 TrigPoly& operator/= ( const CoefficientType & scalar )

◆ operator=() [1/2]

 TrigPoly& operator= ( const TrigPoly< _CoefficientType > & )
default

◆ operator=() [2/2]

 TrigPoly& operator= ( TrigPoly< _CoefficientType > && )
default

◆ operator==()

 bool operator== ( const TrigPoly< _CoefficientType > & other ) const

Compares two TrigPolys for equality.

Note that the question of equality of TrigPolys is a bit subtle. It is not immediately clear if two TrigPolys whose poly and sin_cos_map members differ equivalently (eg, a + b (b = cos(a)) and a + c (c = cos(a))) should be considered equal.

For simplicity we only consider exactly equality rather than semantic equivalence. However that decision could reasonably revisited in the future.

◆ poly()

 const PolyType& poly ( void ) const

Returns the underlying Polynomial for this TrigPoly.

◆ sin_cos_map()

 const SinCosMap& sin_cos_map ( void ) const

Returns the SinCosMap for this TrigPoly.

◆ cos

 TrigPoly cos ( const TrigPoly< _CoefficientType > & p )
friend

A version of cos that handles TrigPoly arguments through ADL.

Implements cos(x) for a TrigPoly x.

x must be of degree 0 or 1, and must contain only variables that have entries in its SinCosMap.

◆ operator * [1/2]

 const TrigPoly operator * ( const TrigPoly< _CoefficientType > & p, const CoefficientType & scalar )
friend

◆ operator * [2/2]

 const TrigPoly operator * ( const CoefficientType & scalar, const TrigPoly< _CoefficientType > & p )
friend

◆ operator+ [1/2]

 const TrigPoly operator+ ( const TrigPoly< _CoefficientType > & p, const CoefficientType & scalar )
friend

◆ operator+ [2/2]

 const TrigPoly operator+ ( const CoefficientType & scalar, const TrigPoly< _CoefficientType > & p )
friend

◆ operator- [1/2]

 const TrigPoly operator- ( const TrigPoly< _CoefficientType > & p, const CoefficientType & scalar )
friend

◆ operator- [2/2]

 const TrigPoly operator- ( const CoefficientType & scalar, const TrigPoly< _CoefficientType > & p )
friend

◆ operator<<

 std::ostream& operator<< ( std::ostream & os, const TrigPoly< CoefficientType > & tp )
friend

◆ sin

 TrigPoly sin ( const TrigPoly< _CoefficientType > & p )
friend

A version of sin that handles TrigPoly arguments through ADL.

Implements sin(x) for a TrigPoly x.

x must be of degree 0 or 1, and must contain only variables that have entries in its SinCosMap.

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