Honeycomb  0.1
Component-Model Framework
Public Types | Static Public Member Functions | List of all members
honey::Polynomial< Real > Class Template Reference

Polynomial algorithms. More...

#include <Polynomial.h>

Public Types

typedef Vec< 2, RealVec2
 
typedef Vec< 3, RealVec3
 
typedef Vec< 4, RealVec4
 
typedef Vec< 5, RealVec5
 
typedef Vec< matrix::dynamic, RealVec
 

Static Public Member Functions

template<class T >
static Real eval (const VecBase< T > &c, Real x)
 Evaluate a polynomial at x. More...
 
template<class T >
static tuple< T, int > compress (const VecBase< T > &c, Real epsilon=Real_::epsilon)
 Reduce the degree by eliminating all near-zero leading coefficients and by making the leading coefficient one. More...
 
template<class T >
static auto derivative (const VecBase< T > &c) -> honey::Vec<(T::s_size==matrix::dynamic?matrix::dynamic:T::s_size-1), Real >
 Get the derivative of a polynomial. Returns a polynomial with 1 degree less. More...
 
static tuple< Real, int > roots (const Vec2 &c, Real epsilon=Real_::epsilon)
 Find roots using an algebraic closed form expression. Solves the linear equation: $ c_1 x + c_0 = 0 $. More...
 
static tuple< Vec2, int > roots (const Vec3 &c, Real epsilon=Real_::epsilon)
 Solves the quadratic equation: $ c_2 x^2 + c_1 x + c_0 = 0 $. More...
 
static tuple< Vec3, int > roots (const Vec4 &c, Real epsilon=Real_::epsilon)
 Solves the cubic equation: $ c_3 x^3 + c_2 x^2 + c_1 x + c_0 = 0 $. More...
 
static tuple< Vec4, int > roots (const Vec5 &c, Real epsilon=Real_::epsilon)
 Solves the quartic equation: $ c_4 x^4 + c_3 x^3 + c_2 x^2 + c_1 x + c_0 = 0 $. More...
 
static tuple< Vec, int > roots (const Vec &c, Real epsilon=Real_::epsilon, int iterMax=30)
 Find roots of generic polynomial using bisection. More...
 
static tuple< Vec, int > rootsInRange (const Vec &c, Real min, Real max, Real epsilon=Real_::epsilon, int iterMax=30)
 Find roots of generic polynomial within range using bisection. More...
 
template<class T >
static tuple< Real, RealrootBounds (const VecBase< T > &c, Real epsilon=Real_::epsilon)
 Get lower and upper bounds of root magnitudes. Returns positive range or 0 if polynomial is constant (degree 0). More...
 

Detailed Description

template<class Real>
class honey::Polynomial< Real >

Polynomial algorithms.

A polynomial is represented by a vector of coefficients c. The polynomial's degree is c.size()-1. The lowest degree is at the first index. ex. $ c_2 x^2 + c_1 x + c_0 $

Member Typedef Documentation

template<class Real >
typedef Vec<matrix::dynamic, Real> honey::Polynomial< Real >::Vec
template<class Real >
typedef Vec<2, Real> honey::Polynomial< Real >::Vec2
template<class Real >
typedef Vec<3, Real> honey::Polynomial< Real >::Vec3
template<class Real >
typedef Vec<4, Real> honey::Polynomial< Real >::Vec4
template<class Real >
typedef Vec<5, Real> honey::Polynomial< Real >::Vec5

Member Function Documentation

template<class Real >
template<class T >
static tuple<T, int> honey::Polynomial< Real >::compress ( const VecBase< T > &  c,
Real  epsilon = Real_::epsilon 
)
inlinestatic

Reduce the degree by eliminating all near-zero leading coefficients and by making the leading coefficient one.

Parameters
cCoefficients of the input polynomial
epsilonThreshold to clamp to zero
Return values
coeffCoefficients of the compressed polynomial
degreeDegree of the polynomial in range [-1, c.size()-1] (at degree 0 there is 1 coeff).
template<class Real >
template<class T >
static auto honey::Polynomial< Real >::derivative ( const VecBase< T > &  c) -> honey::Vec<(T::s_size == matrix::dynamic ? matrix::dynamic : T::s_size - 1), Real>
inlinestatic

Get the derivative of a polynomial. Returns a polynomial with 1 degree less.

template<class Real >
template<class T >
static Real honey::Polynomial< Real >::eval ( const VecBase< T > &  c,
Real  x 
)
inlinestatic

Evaluate a polynomial at x.

template<class Real >
template<class T >
static tuple<Real,Real> honey::Polynomial< Real >::rootBounds ( const VecBase< T > &  c,
Real  epsilon = Real_::epsilon 
)
inlinestatic

Get lower and upper bounds of root magnitudes. Returns positive range or 0 if polynomial is constant (degree 0).

template<class Real >
auto honey::Polynomial< Real >::roots ( const Vec2 c,
Real  epsilon = Real_::epsilon 
)
static

Find roots using an algebraic closed form expression. Solves the linear equation: $ c_1 x + c_0 = 0 $.

Return values
roots
rootCount
template<class Real >
auto honey::Polynomial< Real >::roots ( const Vec3 c,
Real  epsilon = Real_::epsilon 
)
static

Solves the quadratic equation: $ c_2 x^2 + c_1 x + c_0 = 0 $.

template<class Real >
auto honey::Polynomial< Real >::roots ( const Vec4 c,
Real  epsilon = Real_::epsilon 
)
static

Solves the cubic equation: $ c_3 x^3 + c_2 x^2 + c_1 x + c_0 = 0 $.

template<class Real >
auto honey::Polynomial< Real >::roots ( const Vec5 c,
Real  epsilon = Real_::epsilon 
)
static

Solves the quartic equation: $ c_4 x^4 + c_3 x^3 + c_2 x^2 + c_1 x + c_0 = 0 $.

template<class Real >
auto honey::Polynomial< Real >::roots ( const Vec c,
Real  epsilon = Real_::epsilon,
int  iterMax = 30 
)
static

Find roots of generic polynomial using bisection.

This algorithm works by first recursively finding the roots of the polynomial's derivative. The roots of the derivative are monotonic ranges over the polynomial, thus these ranges can be searched using bisection.

template<class Real >
auto honey::Polynomial< Real >::rootsInRange ( const Vec c,
Real  min,
Real  max,
Real  epsilon = Real_::epsilon,
int  iterMax = 30 
)
static

Find roots of generic polynomial within range using bisection.


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