12 #ifndef ECL_GEOMETRY_POLYNOMIALS_HPP_ 13 #define ECL_GEOMETRY_POLYNOMIALS_HPP_ 61 template<
unsigned int N>
109 template <
unsigned int N>
153 template<
typename Derived>
176 void shift_horizontal(
const double &shift);
190 Polynomial<N-1> derivative_polynomial;
191 typename Polynomial<N-1>
::Coefficients &derivative_coefficients = derivative_polynomial.coefficients();
192 for (
unsigned int i = 0; i < N; ++i ) {
193 derivative_coefficients[i] = (i+1)*coeff[i+1];
195 return derivative_polynomial;
205 double derivative(
const double &x)
const;
214 double dderivative(
const double &x)
const;
249 double operator ()(
const double &x)
const;
263 template <
typename OutputStream,
unsigned int Degree>
264 friend OutputStream& operator << (OutputStream &ostream, const Polynomial<Degree> &polynomial);
375 double operator ()(
const double& )
const {
395 template <
unsigned int N>
402 for (
unsigned int i = 0; i < N; ++i ) {
405 for ( iter = (pascals_triangle.
begin(i)+1); iter != pascals_triangle.
end(i); ++iter ) {
406 coeff[i] += (*iter)*tmp*coeff[j];
415 template <
unsigned int N>
419 double value = coeff[0];
420 for (
unsigned int i = 1; i <= N; ++i ) {
421 value += coeff[i]*tmp;
426 template <
unsigned int N>
430 return derivative()(x);
436 template <
unsigned int N>
440 return derivative().derivative()(x);
450 template <
typename OutputStream,
unsigned int Degree>
451 OutputStream& operator << (OutputStream &ostream, const Polynomial<Degree> &polynomial)
458 ostream << format(polynomial.coeff[0]);
459 for (
unsigned int i = 1; i <= Degree; ++i) {
460 ostream <<
" + " << format(polynomial.coeff[i]) <<
"x^" << i;
471 namespace blueprints {
639 const double x_f,
const double y_f,
const double ydot_f) :
642 ydot_initial(ydot_i),
709 const double x_f,
const double y_f,
const double yddot_f) :
712 yddot_initial(yddot_i),
727 base_type instantiate();
735 void apply(base_type& polynomial)
const;
785 const double x_f,
const double y_f,
const double ydot_f,
const double yddot_f) :
788 ydot_initial(ydot_i),
789 yddot_initial(yddot_i),
861 static LinearInterpolation Interpolation(
const double x_i,
const double y_i,
const double x_f,
const double y_f);
870 static LinearPointSlopeForm PointSlopeForm(
const double x_f,
const double y_f,
const double slope);
910 const double x_f,
const double y_f,
const double ydot_f);
930 const double x_f,
const double y_f,
const double yddot_f);
971 static QuinticInterpolation Interpolation(
const double x_i,
const double y_i,
const double ydot_i,
const double yddot_i,
972 const double x_f,
const double y_f,
const double ydot_f,
const double yddot_f);
1002 ECL_PUBLIC double operator()(
const double& x_begin,
const double& x_end,
const LinearFunction &
function);
1026 ECL_PUBLIC double operator()(
const double& x_begin,
const double& x_end,
const CubicPolynomial& cubic);
1051 ECL_PUBLIC double operator()(
const double& x_begin,
const double& x_end,
const LinearFunction &
function);
1075 ECL_PUBLIC double operator()(
const double& x_begin,
const double& x_end,
const CubicPolynomial& cubic);
1109 bool fail()
const {
return last_operation_failed; }
1135 ECL_PUBLIC LinearFunction operator()(
const QuadraticPolynomial &p,
const double &factor,
double &remainder);
1155 ECL_PUBLIC QuadraticPolynomial operator()(
const CubicPolynomial &p,
const double &factor,
double &remainder);
1245 point = intersection(f,g);
1264 static double Minimum(
const double& x_begin,
const double& x_end,
const LinearFunction &
function) {
1272 static double Maximum(
const double& x_begin,
const double& x_end,
const LinearFunction &
function) {
1299 static LinearFunction
Division(
const QuadraticPolynomial &p,
const double &factor,
double &remainder) {
1328 static QuadraticPolynomial
Division(
const CubicPolynomial &p,
const double &factor,
double &remainder) {
1337 static double Minimum(
const double& x_begin,
const double& x_end,
const CubicPolynomial &
function) {
1345 static double Maximum(
const double& x_begin,
const double& x_end,
const CubicPolynomial &
function) {
Blueprint for interpolating a cubic polynomial between end point conditions.
virtual ~CubicSecondDerivativeInterpolation()
Polynomial< N-1 > derivative() const
Generates the derivative polynomial.
static CartesianPoint2d Intersection(const LinearFunction &f, const LinearFunction &g)
Redirections intersection operator for linear functions.
Primary template functor for the maximum of a continuous function.
Embedded control libraries.
virtual ~BluePrintFactory()
#define ecl_throw(exception)
Primary template functor for the roots of a function (x-axis intercepts).
virtual ~BluePrintFactory()
void implementApply(BaseType &object) const
Blueprint for interpolating a cubic polynomial between end point conditions.
Mathematical minimum on a compact interval for cubic polynomials.
static double Maximum(const double &x_begin, const double &x_end, const LinearFunction &function)
Redirections the maximum operator for linear functions.
ecl::CubicPolynomial base_type
Abstract representation of the class to be instantiated/configured.
static Array< double > Roots(const LinearFunction &function)
Root of the linear function.
Blueprint for interpolating a linear function connecting end point conditions.
X axis intercepts for linear functions.
#define ecl_geometry_PUBLIC
virtual ~BluePrintFactory()
bool fail() const
Boolean flag identifying if the last operation failed or not.
static double Minimum(const double &x_begin, const double &x_end, const LinearFunction &function)
Redirections the minimum operator for linear functions.
virtual ~FunctionMath()
Default constructor.
static QuadraticPolynomial Division(const CubicPolynomial &p, const double &factor, double &remainder)
Division by a factor (synthetic division algorithm).
virtual ~QuinticInterpolation()
Templatised specialisations for pascal's triangle.
ecl::CubicPolynomial base_type
Abstract representation of the class to be instantiated/configured.
Polynomial()
Default constructor.
double dderivative(const double &x) const
Access the second derivative directly.
const Coefficients & coefficients() const
Non-modifiable handle to the coefficient array.
Array< double, 1 > Coefficients
The coefficient container storage type.
LinearInterpolation(const double x_i, const double y_i, const double x_f, const double y_f)
Constructor that properly configures/initialises the blueprint.
Synthetic division between cubic and a factor.
Primary template functor for polynomial division.
Polynomial< 1 > LinearFunction
Mathematical term for 1st order polynomials.
Primary template functor for the intersection of like functions.
Coefficients & coefficients()
Handle to the coefficient array, use to initialise the polynomial.
Polynomial< 0 > derivative() const
Derivative of a zero'th order polynomial is always zero.
X axis intercepts for quadratics.
Mathematical maximum on a compact interval for linear functions.
virtual ~CubicDerivativeInterpolation()
X axis intercepts for cubic polynomials.
Polynomial< 2 > QuadraticPolynomial
Mathematical term for 2nd order polynomials.
ecl::LinearFunction base_type
Abstract representation of the class to be instantiated/configured.
CubicDerivativeInterpolation(const double x_i, const double y_i, const double ydot_i, const double x_f, const double y_f, const double ydot_f)
Constructor that properly configures/initialises the blueprint.
const Coefficients & coefficients() const
Non-modifiable handle to the coefficient array.
CubicSecondDerivativeInterpolation(const double x_i, const double y_i, const double yddot_i, const double x_f, const double y_f, const double yddot_f)
Constructor that properly configures/initialises the blueprint.
Cartesian point representations.
Intersection of two linear functions.
Mathematical minimum on a compact interval for linear functions.
static double Minimum(const double &x_begin, const double &x_end, const CubicPolynomial &function)
Redirections the minimum operator for cubics.
Coefficients & coefficients()
Handle to the coefficient array, use to initialise the polynomial.
void shift_horizontal(const double &shift)
Horizontal shift transform.
Specialisation for the zero-th order polynomial.
Synthetic division between quadratic and a factor.
bool last_operation_failed
Blueprint for interpolating a quintic polynomial between end point conditions.
Mathematical maximum on a compact interval for cubic polynomials.
virtual ~LinearInterpolation()
static double Maximum(const double &x_begin, const double &x_end, const CubicPolynomial &function)
Redirections the maximum operator for cubics.
#define ecl_compile_time_concept_check(Model)
double dderivative(const double &) const
Access the second derivative directly (always returns 0)..
Functors for evaluating various mathematical properties of functions.
virtual ~FunctionMath()
Default constructor.
double operator()(const double &x) const
Access the value of the polynomial at a certain point.
static LinearFunction Division(const QuadraticPolynomial &p, const double &factor, double &remainder)
Division by a factor (synthetic division algorithm).
Array< int,(N+2) *(N+1)/2 >::const_iterator const_iterator
Utilise the array's iterator for parsing the triangle.
void shift_horizontal(const double &)
Horizontal shift transform.
static Array< double > Roots(const CubicPolynomial &p)
Real roots of the cubic.
const_iterator end(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [end].
Holds the coefficients for pascal's triangle up to row N.
Used as a parent to load function math into function classes.
ecl::QuinticPolynomial base_type
Abstract representation of the class to be instantiated/configured.
Polynomial()
Default constructor.
Generic container storing a cartesian point of dimension N.
virtual ~FunctionMath()
Default constructor.
QuinticInterpolation(const double x_i, const double y_i, const double ydot_i, const double yddot_i, const double x_f, const double y_f, const double ydot_f, const double yddot_f)
Constructor that properly configures/initialises the blueprint.
#define ecl_catch(exception)
const_iterator begin(unsigned int index=0) const
Iterator generator for diagonals of pascals triangle [begin].
static Array< double > Roots(const QuadraticPolynomial &p)
Real roots of the quadratic.
double derivative(const double &) const
Access the derivative directly (always returns 0).
Polynomial(const BluePrint< Derived > &blueprint)
Blueprint constructor.
Polynomial< 3 > CubicPolynomial
Mathematical term for 3rd order polynomials.
Array< double, N+1 > Coefficients
The coefficient container storage type.
Representation of a polynomial function of n-th degree.
Primary template functor for the minimum of a continuous function.
Polynomial< 5 > QuinticPolynomial
Mathematical term for 5th order polynomials.