Gazebo Math

API Reference

8.1.0
Polynomial3< T > Class Template Reference

The Polynomial3 class represents a cubic polynomial with real coefficients p(x) = c0 x^3 + c1 x^2 + c2 x + c3. More...

#include <gz/math/Polynomial3.hh>

Public Member Functions

 Polynomial3 ()=default
 Constructor.
 
 Polynomial3 (Vector4< T > _coeffs)
 Constructor.
 
const Vector4< T > & Coeffs () const
 Get the polynomial coefficients.
 
Evaluate (const T &_x) const
 Evaluate the polynomial at _x For non-finite _x, this function computes p(z) as z tends to _x.
 
Minimum () const
 Compute polynomial minimum.
 
Minimum (const Interval< T > &_interval) const
 Compute polynomial minimum in an _interval
 
Minimum (const Interval< T > &_interval, T &_xMin) const
 Compute polynomial minimum in an _interval
 
Minimum (T &_xMin) const
 Compute polynomial minimum.
 
operator() (const T &_x) const
 Call operator overload.
 
void Print (std::ostream &_out, const std::string &_x="x") const
 Prints polynomial as p(_x) to _out stream.
 

Static Public Member Functions

static Polynomial3 Constant (T _value)
 Make a constant polynomial.
 

Detailed Description

template<typename T>
class gz::math::Polynomial3< T >

The Polynomial3 class represents a cubic polynomial with real coefficients p(x) = c0 x^3 + c1 x^2 + c2 x + c3.

Example

#include <iostream>
int main(int argc, char **argv)
{
// A default constructed polynomial should have zero coefficients.
std::cout << "A default constructed polynomial is always: "
// A constant polynomial only has an independent term.
std::cout << "A constant polynomial only has an independent term: "
<< gz::math::Polynomial3d::Constant(-1.) << std::endl;
// A cubic polynomial may be incomplete.
gz::math::Vector4d(1., 0., -1., 2.));
std::cout << "A cubic polynomial may be incomplete: " << p << std::endl;
// A polynomial can be evaluated.
const double x = 0.5;
std::cout << "Evaluating " << p << " at " << x
<< " yields " << p(x) << std::endl;
// A polynomial can be queried for its minimum in a given interval,
// as well as for its global minimum (which may not always be finite).
gz::math::Intervald::Closed(-1, 1.);
std::cout << "The minimum of " << p << " in the " << interval
<< " interval is " << p.Minimum(interval) << std::endl;
std::cout << "The global minimum of " << p
<< " is " << p.Minimum() << std::endl;
gz::math::Vector4d(0., 1., 2., 1.));
std::cout << "The minimum of " << q << " in the " << interval
<< " interval is " << q.Minimum(interval) << std::endl;
std::cout << "The global minimum of " << q
<< " is " << q.Minimum() << std::endl;
}

Constructor & Destructor Documentation

◆ Polynomial3() [1/2]

template<typename T >
Polynomial3 ( )
default

Constructor.

Referenced by Polynomial3< T >::Constant().

◆ Polynomial3() [2/2]

template<typename T >
Polynomial3 ( Vector4< T >  _coeffs)
inlineexplicit

Constructor.

Parameters
[in]_coeffscoefficients c0 through c3, left to right

Member Function Documentation

◆ Coeffs()

template<typename T >
const Vector4< T > & Coeffs ( ) const
inline

Get the polynomial coefficients.

Returns
this polynomial coefficients

◆ Constant()

template<typename T >
static Polynomial3 Constant ( _value)
inlinestatic

Make a constant polynomial.

Returns
a p(x) = _value polynomial

References Polynomial3< T >::Polynomial3().

◆ Evaluate()

template<typename T >
T Evaluate ( const T &  _x) const
inline

Evaluate the polynomial at _x For non-finite _x, this function computes p(z) as z tends to _x.

Parameters
[in]_xpolynomial argument
Returns
the result of evaluating p(_x)

References std::copysign(), numeric_limits::epsilon(), std::isfinite(), gz::math::isnan(), and std::isnan().

Referenced by Polynomial3< T >::Minimum(), and Polynomial3< T >::operator()().

◆ Minimum() [1/4]

template<typename T >
T Minimum ( ) const
inline

Compute polynomial minimum.

Returns
the polynomial minimum (may not be finite)

References Polynomial3< T >::Minimum().

Referenced by Polynomial3< T >::Minimum(), Polynomial3< T >::Minimum(), and Polynomial3< T >::Minimum().

◆ Minimum() [2/4]

template<typename T >
T Minimum ( const Interval< T > &  _interval) const
inline

Compute polynomial minimum in an _interval

Parameters
[in]_intervalpolynomial argument interval to check
Returns
the polynomial minimum in the given interval (may not be finite), or NaN if the interval is empty

References Polynomial3< T >::Minimum().

◆ Minimum() [3/4]

template<typename T >
T Minimum ( const Interval< T > &  _interval,
T &  _xMin 
) const
inline

Compute polynomial minimum in an _interval

Parameters
[in]_intervalpolynomial argument interval to check
[out]_xMinpolynomial argument that yields minimum, or NaN if the interval is empty
Returns
the polynomial minimum in the given interval, or NaN if the interval is empty

References numeric_limits::epsilon(), Polynomial3< T >::Evaluate(), numeric_limits::quiet_NaN(), and std::sqrt().

◆ Minimum() [4/4]

template<typename T >
T Minimum ( T &  _xMin) const
inline

Compute polynomial minimum.

Parameters
[out]_xMinpolynomial argument that yields minimum
Returns
the polynomial minimum (may not be finite)

References Polynomial3< T >::Minimum().

◆ operator()()

template<typename T >
T operator() ( const T &  _x) const
inline

Call operator overload.

See also
Polynomial3::Evaluate()

References Polynomial3< T >::Evaluate().

◆ Print()

template<typename T >
void Print ( std::ostream _out,
const std::string _x = "x" 
) const
inline

Prints polynomial as p(_x) to _out stream.

Parameters
[in]_outOutput stream to print to
[in]_xArgument name to be used

References numeric_limits::epsilon().


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