Drake
TrigPoly< _CoefficientType > Class Template Reference

A scalar multi-variate polynomial containing sines and cosines. More...

#include <drake/util/TrigPoly.h>

Classes

struct  Product
 
struct  SinCosVars
 

Public Types

typedef _CoefficientType CoefficientType
 
typedef Polynomial< CoefficientTypePolyType
 
typedef PolyType::VarType VarType
 
typedef std::map< VarType, SinCosVarsSinCosMap
 

Public Member Functions

 TrigPoly ()
 Constructs a vacuous TrigPoly. More...
 
 TrigPoly (const CoefficientType &scalar)
 Constructs a constant TrigPoly. 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...
 
const PolyTypegetPolynomial (void) const
 Returns the underlying Polynomial for this TrigPoly. More...
 
const SinCosMapgetSinCosMap (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
 

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)
 

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; TODO(ggould-tri) fix this in the future.

Member Typedef Documentation

typedef _CoefficientType CoefficientType
typedef std::map<VarType, SinCosVars> SinCosMap
typedef PolyType::VarType VarType

Constructor & Destructor Documentation

TrigPoly ( )
inline

Constructs a vacuous TrigPoly.

Here is the caller graph for this function:

TrigPoly ( const CoefficientType scalar)
inline

Constructs a constant TrigPoly.

TrigPoly ( const PolyType p,
const SinCosMap _sin_cos_map 
)
inline

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Member Function Documentation

Product<CoefficientType, T>::type evaluateMultivariate ( const std::map< VarType, T > &  var_values) const
inline

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.

Here is the call graph for this function:

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

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.

Here is the call graph for this function:

const PolyType& getPolynomial ( void  ) const
inline

Returns the underlying Polynomial for this TrigPoly.

const SinCosMap& getSinCosMap ( void  ) const
inline

Returns the SinCosMap for this TrigPoly.

std::set<VarType> getVariables ( ) const
inline

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

const TrigPoly operator* ( const TrigPoly< _CoefficientType > &  other) const
inline
TrigPoly& operator*= ( const TrigPoly< _CoefficientType > &  other)
inline
TrigPoly& operator*= ( const CoefficientType scalar)
inline
const TrigPoly operator+ ( const TrigPoly< _CoefficientType > &  other) const
inline
TrigPoly& operator+= ( const TrigPoly< _CoefficientType > &  other)
inline
TrigPoly& operator+= ( const CoefficientType scalar)
inline
const TrigPoly operator- ( const TrigPoly< _CoefficientType > &  other) const
inline
const TrigPoly operator- ( ) const
inline
TrigPoly& operator-= ( const TrigPoly< _CoefficientType > &  other)
inline
TrigPoly& operator-= ( const CoefficientType scalar)
inline
const TrigPoly operator/ ( const CoefficientType scalar) const
inline
TrigPoly& operator/= ( const CoefficientType scalar)
inline
bool operator== ( const TrigPoly< _CoefficientType > &  other) const
inline

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.

Friends And Related Function Documentation

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.

const TrigPoly operator* ( const TrigPoly< _CoefficientType > &  p,
const CoefficientType scalar 
)
friend
const TrigPoly operator* ( const CoefficientType scalar,
const TrigPoly< _CoefficientType > &  p 
)
friend
const TrigPoly operator+ ( const TrigPoly< _CoefficientType > &  p,
const CoefficientType scalar 
)
friend
const TrigPoly operator+ ( const CoefficientType scalar,
const TrigPoly< _CoefficientType > &  p 
)
friend
const TrigPoly operator- ( const TrigPoly< _CoefficientType > &  p,
const CoefficientType scalar 
)
friend
const TrigPoly operator- ( const CoefficientType scalar,
const TrigPoly< _CoefficientType > &  p 
)
friend
std::ostream& operator<< ( std::ostream &  os,
const TrigPoly< CoefficientType > &  tp 
)
friend
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: