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 >

List of all members.

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

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.
coefs_t impl_translate (value_type t1) const
 Polynomial (value_type t0, special_polynomials key)
 Special constructor for Monomial<N> and some operators.

Static Protected Attributes

static const int order_ = N
 order of the polynomial.

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


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

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::BSpline< N >::cox_de_boor(), 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 >::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 >::min_t roboptim::trajectory::Polynomial< N >::min ( const interval_t interval) const

Compute the minimum of the polynomial on an interval.

Parameters:
intervaltime interval.
Returns:
pair containing t_min and the associated minimum of the polynomial on the interval.
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>
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>
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 ( ) [inline, static]

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>
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+(), 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 [static, protected]

order of the polynomial.

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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines