All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
roboptim::trajectory::Polynomial< N > Class Template Reference

Polynomial of degree at most N (N >= 0). More...

#include <roboptim/trajectory/polynomial.hh>

Inheritance diagram for roboptim::trajectory::Polynomial< N >:
roboptim::trajectory::Monomial< N >

Public Types

typedef Function::interval_t interval_t
 
typedef std::vector< value_type > roots_t
 Type of the vector of roots. More...
 
typedef Eigen::Matrix
< value_type, N+1, 1 > 
coefs_t
 Fixed-size coefficient vector (N+1 if N is the polynomial degree). More...
 
typedef std::vector< value_type > values_t
 Type of the critical points. More...
 
typedef std::pair< value_type,
value_type > 
max_t
 Type of a maximum query: (t_max, P(t_max)) More...
 
typedef std::pair< value_type,
value_type > 
min_t
 Type of a minimum query: (t_min, P(t_min)) More...
 
typedef ::roboptim::Polynomial
< Function::traits_t > 
polynomialFunction_t
 Polynomial function. More...
 

Public Member Functions

 ROBOPTIM_FUNCTION_FWD_TYPEDEFS_ (Function)
 
 BOOST_STATIC_ASSERT (N >=0)
 Polynomial degree >= 0. More...
 
 Polynomial ()
 Default constructor: return a null polynomial. More...
 
 Polynomial (value_type t0, const_vector_ref coefs)
 Construct of a polynomial from its center and its coefficients. More...
 
 Polynomial (value_type t0,...)
 Variadic constructor. More...
 
template<int M>
 Polynomial (const Polynomial< M > &p)
 Copy constructor of polynomials of different orders. More...
 
Polynomial< N > translate (value_type t1) const
 Return a new polynomial translated from (t-t₀) to (t-t₁). More...
 
void translateInPlace (value_type t1)
 Translate the polynomial (in place) from (t-t₀) to (t-t₁). More...
 
template<int K>
Polynomial< N-K > derivative () const
 Compute the derivative polynomial of a given order. More...
 
value_type derivative (value_type t, size_type order=1) const
 Evaluate the derivative of a given order. More...
 
template<int M>
Polynomial< N+M > operator* (const Polynomial< M > &poly) const
 Multiply polynomials of different orders. More...
 
Polynomial< N > operator+ (const Polynomial< N > &poly) const
 Addition of polynomials. More...
 
Polynomial< N > operator- (const Polynomial< N > &poly) const
 Subtraction of polynomials. More...
 
Polynomial< N > operator* (value_type lambda) const
 Scalar multiplication of a polynomial. More...
 
void operator+= (const Polynomial< N > &poly)
 Addition of polynomials. More...
 
value_type operator() (value_type t) const
 Evaluate the polynomial with Horner's method. More...
 
const coefs_tcoefs () const
 Const getter to coefs. More...
 
coefs_tcoefs ()
 Getter to coefs. More...
 
value_type t0 () const
 Const getter to t0. More...
 
value_type & t0 ()
 Reference to t0. More...
 
value_type operator[] (int i) const
 Get the i-th polynomial coefficient. More...
 
roots_t realRoots (value_type epsilon=1e-6) const
 Return the real roots of the polynomial. More...
 
values_t critPoints (const interval_t &interval) const
 Compute the critical values of the polynomial on an interval. More...
 
min_t min (const interval_t &interval, bool acceptConstant=true) const
 Compute the minimum of the polynomial on an interval. More...
 
max_t max (const interval_t &interval, bool acceptConstant=true) const
 Compute the maximum of the polynomial on an interval. More...
 
bool isNull (value_type epsilon=Function::epsilon()) const
 Return whether the polynomial is null. More...
 
bool isConstant (value_type epsilon=Function::epsilon()) const
 Return whether the polynomial is constant. More...
 
bool isLinear (value_type epsilon=Function::epsilon()) const
 Return whether the polynomial is linear. More...
 
int trueOrder (value_type epsilon=Function::epsilon()) const
 Return the "true" order of the polynomial. More...
 
polynomialFunction_t asFunction () const
 Get the equivalent Polynomial function. More...
 
virtual std::ostream & print (std::ostream &o) const
 Print the polynomial. More...
 

Static Public Member Functions

static int order ()
 Return the order of such a polynomial. More...
 

Protected Types

enum  special_polynomials {
  all_zero_coefficients = 0,
  monomial_coefficients = 1
}
 Enum for special polynomials. More...
 

Protected Member Functions

value_type impl_derivative (value_type t, size_type order, size_type start_coef=0) const
 
template<int K>
Polynomial< N-K > impl_derivative () const
 Implementation of the compile-time derivative. More...
 
coefs_t impl_translate (value_type t1) const
 
 Polynomial (value_type t0, special_polynomials key)
 Special constructor for Monomial<N> and some operators. More...
 

Static Protected Attributes

static const int order_ = N
 order of the polynomial. More...
 

Detailed Description

template<int N>
class roboptim::trajectory::Polynomial< N >

Polynomial of degree at most N (N >= 0).

\[ P (t) = \sum_{i=0}^{N} a_i (t-t_0)^i \]

Member Typedef Documentation

template<int N>
typedef Eigen::Matrix<value_type, N+1, 1> roboptim::trajectory::Polynomial< N >::coefs_t

Fixed-size coefficient vector (N+1 if N is the polynomial degree).

template<int N>
typedef Function::interval_t roboptim::trajectory::Polynomial< N >::interval_t
template<int N>
typedef std::pair<value_type, value_type> roboptim::trajectory::Polynomial< N >::max_t

Type of a maximum query: (t_max, P(t_max))

template<int N>
typedef std::pair<value_type, value_type> roboptim::trajectory::Polynomial< N >::min_t

Type of a minimum query: (t_min, P(t_min))

template<int N>
typedef ::roboptim::Polynomial<Function::traits_t> roboptim::trajectory::Polynomial< N >::polynomialFunction_t

Polynomial function.

template<int N>
typedef std::vector<value_type> roboptim::trajectory::Polynomial< N >::roots_t

Type of the vector of roots.

template<int N>
typedef std::vector<value_type> roboptim::trajectory::Polynomial< N >::values_t

Type of the critical points.

Member Enumeration Documentation

Enum for special polynomials.

Enumerator
all_zero_coefficients 

Null polynomial: 0.

monomial_coefficients 

Monomial polynomial: (t-t₀)

Constructor & Destructor Documentation

template<int N>
roboptim::trajectory::Polynomial< N >::Polynomial ( )

Default constructor: return a null polynomial.

template<int N>
roboptim::trajectory::Polynomial< N >::Polynomial ( value_type  t0,
const_vector_ref  coefs 
)

Construct of a polynomial from its center and its coefficients.

Parameters
t0polynomial of (t-t₀).
coefspolynomial coefficients.

References roboptim::trajectory::Polynomial< N >::coefs().

template<int N>
roboptim::trajectory::Polynomial< N >::Polynomial ( value_type  t0,
  ... 
)

Variadic constructor.

Note: this is a legacy constructor used to keep Polynomial3's API.

Parameters
t0polynomial of (t-t₀).
...variadic arguments containing [a₀,a₁,...,a_N]
template<int N>
template<int M>
roboptim::trajectory::Polynomial< N >::Polynomial ( const Polynomial< M > &  p)

Copy constructor of polynomials of different orders.

Warning
If N < M, coefficients of higher degrees will be discarded. This is only valid if you are considering |t-t₀|«1.
Template Parameters
Mdegree of the copied polynomial.
Parameters
pcopied polynomial.

References roboptim::trajectory::Polynomial< N >::coefs().

template<int N>
roboptim::trajectory::Polynomial< N >::Polynomial ( value_type  t0,
special_polynomials  key 
)
protected

Special constructor for Monomial<N> and some operators.

Parameters
t0
keyone of all_zero_coefficients, monomial_coefficients.

References roboptim::trajectory::Polynomial< N >::all_zero_coefficients, and roboptim::trajectory::Polynomial< N >::monomial_coefficients.

Member Function Documentation

template<int N>
Polynomial< N >::polynomialFunction_t roboptim::trajectory::Polynomial< N >::asFunction ( ) const

Get the equivalent Polynomial function.

This can be used for all the methods that expect a RobOptim function (e.g. plotting).

Returns
Polynomial function with the appropriate coefficients set.
template<int N>
roboptim::trajectory::Polynomial< N >::BOOST_STATIC_ASSERT ( N >=  0)

Polynomial degree >= 0.

template<int N>
const Polynomial< N >::coefs_t & roboptim::trajectory::Polynomial< N >::coefs ( ) const

Const getter to coefs.

Returns
const reference to polynomial coefficients.

Referenced by roboptim::trajectory::Polynomial< N >::operator*(), and roboptim::trajectory::Polynomial< N >::Polynomial().

template<int N>
Polynomial< N >::coefs_t & roboptim::trajectory::Polynomial< N >::coefs ( )

Getter to coefs.

Returns
reference to polynomial coefficients.
template<int N>
Polynomial< N >::values_t roboptim::trajectory::Polynomial< N >::critPoints ( const interval_t interval) const

Compute the critical values of the polynomial on an interval.

Parameters
intervaltime interval.
Returns
vector containing the critical values of the polynomial on the interval. Used by the min and max function.
Exceptions
std::runtime_errorinvalid polynomial. This is the case for constant polynomials since there is an infinity of critical points. This can be tested before calling min().
template<int N>
template<int K>
Polynomial< N-K > roboptim::trajectory::Polynomial< N >::derivative ( ) const
template<int N>
Polynomial< N >::value_type roboptim::trajectory::Polynomial< N >::derivative ( value_type  t,
size_type  order = 1 
) const

Evaluate the derivative of a given order.

Parameters
ttime of the evaluation.
orderorder of the derivative.
Returns
derivative of a given order evaluated at t.
template<int N>
Polynomial< N >::value_type roboptim::trajectory::Polynomial< N >::impl_derivative ( value_type  t,
size_type  order,
size_type  start_coef = 0 
) const
protected
template<int N>
template<int K>
Polynomial< N-K > roboptim::trajectory::Polynomial< N >::impl_derivative ( ) const
protected

Implementation of the compile-time derivative.

Template Parameters
Korder of the derivation.
Returns
K-th derivative.
template<int N>
Polynomial< N >::coefs_t roboptim::trajectory::Polynomial< N >::impl_translate ( value_type  t1) const
protected
template<int N>
bool roboptim::trajectory::Polynomial< N >::isConstant ( value_type  epsilon = Function::epsilon ()) const

Return whether the polynomial is constant.

Parameters
epsilonepsilon used.
Returns
true if the polynomial is constant, false otherwise.
template<int N>
bool roboptim::trajectory::Polynomial< N >::isLinear ( value_type  epsilon = Function::epsilon ()) const

Return whether the polynomial is linear.

Parameters
epsilonepsilon used.
Returns
true if the polynomial is linear, false otherwise.
template<int N>
bool roboptim::trajectory::Polynomial< N >::isNull ( value_type  epsilon = Function::epsilon ()) const

Return whether the polynomial is null.

Parameters
epsilonepsilon used.
Returns
true if the polynomial is null, false otherwise.
template<int N>
Polynomial< N >::max_t roboptim::trajectory::Polynomial< N >::max ( const interval_t interval,
bool  acceptConstant = true 
) const

Compute the maximum of the polynomial on an interval.

Parameters
intervaltime interval.
acceptConstantboolean allowing constant polynomials.
Returns
pair containing t_max and the associated maximum of the polynomial on the interval. If the polynomial is constant and acceptConstant is not set to false, the call returns a couple of the middle of interval and the value of the polynomial.
Exceptions
std::runtime_errorinvalid polynomial. This is the case for constant polynomials if acceptConstant is set to false, since there is an infinity of critical points.
template<int N>
Polynomial< N >::min_t roboptim::trajectory::Polynomial< N >::min ( const interval_t interval,
bool  acceptConstant = true 
) const

Compute the minimum of the polynomial on an interval.

Parameters
intervaltime interval.
acceptConstantboolean allowing constant polynomials.
Returns
pair containing t_min and the associated minimum of the polynomial on the interval. If the polynomial is constant and acceptConstant is not set to false, the call returns a couple of the middle of interval and the value of the polynomial.
Exceptions
std::runtime_errorinvalid polynomial. This is the case for constant polynomials if acceptConstant is set to false, since there is an infinity of critical points.
template<int N>
Polynomial< N >::value_type roboptim::trajectory::Polynomial< N >::operator() ( value_type  t) const

Evaluate the polynomial with Horner's method.

Parameters
tpoint of evaluation.
Returns
P(t)
template<int N>
template<int M>
Polynomial< N+M > roboptim::trajectory::Polynomial< N >::operator* ( const Polynomial< M > &  poly) const

Multiply polynomials of different orders.

Template Parameters
Morder of the polynomial.
Parameters
polypolynomial to multiply.
Returns
P₀P₁

References roboptim::trajectory::Polynomial< N >::coefs(), and roboptim::trajectory::Polynomial< N >::translate().

template<int N>
Polynomial< N > roboptim::trajectory::Polynomial< N >::operator* ( value_type  lambda) const

Scalar multiplication of a polynomial.

Parameters
lambdascalar.
Returns
λP
template<int N>
Polynomial< N > roboptim::trajectory::Polynomial< N >::operator+ ( const Polynomial< N > &  poly) const

Addition of polynomials.

Parameters
polypolynomial to add.
Returns
P₀ + P₁

References roboptim::trajectory::Polynomial< N >::translate().

template<int N>
void roboptim::trajectory::Polynomial< N >::operator+= ( const Polynomial< N > &  poly)

Addition of polynomials.

Parameters
polypolynomial to add.

References roboptim::trajectory::Polynomial< N >::translate().

template<int N>
Polynomial< N > roboptim::trajectory::Polynomial< N >::operator- ( const Polynomial< N > &  poly) const

Subtraction of polynomials.

Parameters
polypolynomial to subtract.
Returns
P₀ - P₁

References roboptim::trajectory::Polynomial< N >::translate().

template<int N>
Polynomial< N >::value_type roboptim::trajectory::Polynomial< N >::operator[] ( int  i) const

Get the i-th polynomial coefficient.

Parameters
inumber of the coefficient to get.
Returns
i-th polynomial coefficient αi, with: α_i (t-t₀)^i
template<int N>
static int roboptim::trajectory::Polynomial< N >::order ( )
inlinestatic

Return the order of such a polynomial.

Returns
order of such a polynomial.

References roboptim::trajectory::Polynomial< N >::order_.

template<int N>
std::ostream & roboptim::trajectory::Polynomial< N >::print ( std::ostream &  o) const
virtual

Print the polynomial.

Parameters
ooutput stream.
Returns
output stream.
template<int N>
Polynomial< N >::roots_t roboptim::trajectory::Polynomial< N >::realRoots ( value_type  epsilon = 1e-6) const

Return the real roots of the polynomial.

Warning
This function relies on Eigen's experimental polynomial solver. The polynomial should not be null or constant.
Parameters
epsilonepsilon used for testing constant polynomials.
Returns
vector of the real roots of the polynomial.
Exceptions
std::runtime_errorinvalid polynomial (e.g. null/constant).
template<int N>
roboptim::trajectory::Polynomial< N >::ROBOPTIM_FUNCTION_FWD_TYPEDEFS_ ( Function  )
template<int N>
Polynomial< N >::value_type roboptim::trajectory::Polynomial< N >::t0 ( ) const

Const getter to t0.

Returns
t0.
template<int N>
Polynomial< N >::value_type & roboptim::trajectory::Polynomial< N >::t0 ( )

Reference to t0.

Returns
reference to t0.
template<int N>
Polynomial< N > roboptim::trajectory::Polynomial< N >::translate ( value_type  t1) const

Return a new polynomial translated from (t-t₀) to (t-t₁).

Parameters
t1new center.
Returns
polynomial translated to (t-t₁)

Referenced by roboptim::trajectory::Polynomial< N >::operator*(), roboptim::trajectory::Polynomial< N >::operator+(), roboptim::trajectory::Polynomial< N >::operator+=(), and roboptim::trajectory::Polynomial< N >::operator-().

template<int N>
void roboptim::trajectory::Polynomial< N >::translateInPlace ( value_type  t1)

Translate the polynomial (in place) from (t-t₀) to (t-t₁).

Parameters
t1new center.
template<int N>
int roboptim::trajectory::Polynomial< N >::trueOrder ( value_type  epsilon = Function::epsilon ()) const

Return the "true" order of the polynomial.

Leading coefficients may be null, which c

Returns
degree for the highest exponent with a nonzero coeffcient.

Member Data Documentation

template<int N>
const int roboptim::trajectory::Polynomial< N >::order_ = N
staticprotected

order of the polynomial.

Referenced by roboptim::trajectory::Polynomial< N >::order().