Core 1.0
Quadric Class Reference

Quadric polynomials. More...

#include <quadric.h>

Public Member Functions

 Quadric ()
 Empty.
 Quadric (const double &, const double &, const double &)
 Creates a quadric.
 Quadric (const Linear &)
 Creates a quadric from a Linear polynomial.
 ~Quadric ()
 Empty.
constexpr double & operator[] (int)
 Access class components.
constexpr double operator[] (int) const
 Overloaded.
Quadric operator- () const
 Overloaded.
Quadricoperator+= (const Quadric &)
 Destructive sum of two polynomials.
Quadricoperator-= (const Quadric &)
 Destructive difference of two polynomials.
Quadricoperator*= (const double &)
 Scale a polynomial by a double value.
Quadricoperator/= (const double &)
 Scale a polynomial by a double value.
constexpr double operator() (const double &) const
 Evaluates the quadric.
constexpr double Derivative (const double &) const
 Computes the derivative value at a given point.
Linear Prime () const
 Compute the derivative of a quadric, which is a linear expression.
int Solve (double &, double &) const
 Solve quadratic equations.
int Solve (double *) const
 Solve quadratic equations. This function store the sorted roots in an array and returns the number of roots.
int Solve (double *, const double &, const double &) const
 Solve the quadratic equation over a given interval.
void Range (double &, double &, const double &=0.0, const double &=1.0) const
 This function computes the range of values taken by a quadric over a given interval.
double Maximum (const double &=0.0, const double &=1.0) const
 This function computes the maximum value taken by a quadric over a given interval.
double Minimum (const double &=0.0, const double &=1.0) const
 This function computes the minimum value taken by a quadric over a given interval.
double K (const double &, const double &) const
 Compute the Lipschitz constant of the quadric.

Static Public Member Functions

static Quadric Bezier (const double &, const double &, const double &)
 Creates a quadratic Bezier polynomial on interval [0,1].
static double Smooth (const double &, const double &)
 Compute the value of the \(C^1\) smooth interpolating function \((1-x/r)^2\).
static double Smooth (const double &)
 Compute the value of the \(C^1\) smooth interpolating function \((1-x)^2\).
static double SmoothCompact (const double &, const double &)
 Compact support version of the smooth interpolating function Quadric::Smooth().
static double SmoothCompact (const double &, const double &, const double &)
 Compact support version of the smooth interpolating function Quadric::Smooth() with interior and exterior radii.
static double Warp (const double &)
 Unit interval warping function.
static Quadric Bernstein (int)
 Creates a quadric Bernstein polynomial.
static double Bernstein (int, const double &)
 Compute the quadric Bernstein polynomial for a given value.
static Quadric FromRoots (const QVector< double > &)
 Create a quadric from a set of roots.

Static Public Attributes

static double epsilon = 1.0e-16
 Epsilon value used to check discriminant term in the root finding process.

Protected Attributes

double c [3] = { 0.0,0.0,0.0 }
 Array of coefficients.

Friends

Quadric operator+ (const Quadric &u, const Quadric &v)
 Overloaded.
Quadric operator- (const Quadric &v, const Quadric &u)
 Overloaded.
Quadric operator* (const Quadric &p, const double &e)
 Multiply a quadric by a scalar value.
Quadric operator* (const double &a, const Quadric &p)
 Overloaded.
Quadric operator/ (const Quadric &p, const double &a)
 Overloaded.
Quadric operator* (const Linear &u, const Linear &v)
 Multiply two linear polynomials.
std::ostream & operator<< (std::ostream &s, const Quadric &p)
 Overloaded output-stream operator.

Detailed Description

Quadric polynomials.

Constructors should provide the coefficients in descending order. Here is an example of how to code the quadric \(2 x^2 - x + 1\):

Quadric p(2.0,-1.0,1.0);
Quadric()
Empty.
Definition quadric.h:15

Member Function Documentation

◆ Bernstein() [1/2]

Quadric Quadric::Bernstein ( int p)
static

Creates a quadric Bernstein polynomial.

Parameters
pp-th polynomial.

◆ Bernstein() [2/2]

double Quadric::Bernstein ( int p,
const double & x )
static

Compute the quadric Bernstein polynomial for a given value.

Parameters
pp-th polynomial.
xReal.

◆ Bezier()

Quadric Quadric::Bezier ( const double & a,
const double & b,
const double & c )
static

Creates a quadratic Bezier polynomial on interval [0,1].

Parameters
a,b,cThe parameters of the Bézier polynomial.

Parameters are as follows:

\(c(t)=a (1-t)^2+2b t(1-t)+c t^2=(a-2b+c) t^2+2(b-a) t+a\).

◆ Derivative()

double Quadric::Derivative ( const double & x) const
inlineconstexpr

Computes the derivative value at a given point.

If only one evaluation is to be made, this function is more efficient than Prime() and then evaluating the derivative for a given input value.

Parameters
xReal.
See also
Quadric::Prime

◆ FromRoots()

Quadric Quadric::FromRoots ( const QVector< double > & r)
static

Create a quadric from a set of roots.

Parameters
rSet of roots.

Example of how to code the quadric (x-2)(x+1):

Quintic polynomials.
Definition quintic.h:7
static Quintic FromRoots(const QVector< double > &)
Create a quintic from a set of roots.
Definition quintic.cpp:235

◆ K()

double Quadric::K ( const double & a,
const double & b ) const

Compute the Lipschitz constant of the quadric.

Parameters
a,bInterval.

◆ Maximum()

double Quadric::Maximum ( const double & a = 0.0,
const double & b = 1.0 ) const

This function computes the maximum value taken by a quadric over a given interval.

See also
Range
Parameters
a,bInterval.

◆ Minimum()

double Quadric::Minimum ( const double & a = 0.0,
const double & b = 1.0 ) const

This function computes the minimum value taken by a quadric over a given interval.

See also
Range
Parameters
a,bInterval.

◆ Prime()

Linear Quadric::Prime ( ) const
inline

Compute the derivative of a quadric, which is a linear expression.

See also
Quadric::Derivative

◆ Range()

void Quadric::Range ( double & x,
double & y,
const double & a = 0.0,
const double & b = 1.0 ) const

This function computes the range of values taken by a quadric over a given interval.

Bascially computes the roots of the first derivative, and evaluates the polynomial at the roots if they are within the interval bounds.

Parameters
a,bInterval.
x,yReturned range.

◆ Smooth() [1/2]

double Quadric::Smooth ( const double & x)
inlinestatic

Compute the value of the \(C^1\) smooth interpolating function \((1-x)^2\).

See also
Quadric::Smooth(const double&, const double&)
Parameters
xArgument value.

◆ Smooth() [2/2]

double Quadric::Smooth ( const double & x,
const double & r )
inlinestatic

Compute the value of the \(C^1\) smooth interpolating function \((1-x/r)^2\).

See also
Cubic::Smooth(), Quadric::SmoothCompact
Parameters
xArgument value.
rRadius.

◆ SmoothCompact() [1/2]

double Quadric::SmoothCompact ( const double & x,
const double & r )
inlinestatic

Compact support version of the smooth interpolating function Quadric::Smooth().

Return Quadric::Smooth(x/r) if x<r and 0 otherwise.

See also
Cubic::Smooth(), Quadric::Smooth()
Parameters
xArgument value.
rRadius.

◆ SmoothCompact() [2/2]

double Quadric::SmoothCompact ( const double & x,
const double & e,
const double & i )
inlinestatic

Compact support version of the smooth interpolating function Quadric::Smooth() with interior and exterior radii.

See also
Cubic::Smooth(), Quadric::Smooth()
Parameters
xArgument value.
i,eInterior and exterior radii.

◆ Solve() [1/3]

int Quadric::Solve ( double & u,
double & v ) const

Solve quadratic equations.

This function uses two double arguments to store the roots and returns the number of roots.

Parameters
u,vThe two of roots, if they exist.

◆ Solve() [2/3]

int Quadric::Solve ( double * y) const

Solve quadratic equations. This function store the sorted roots in an array and returns the number of roots.

Parameters
yThe array of roots.

◆ Solve() [3/3]

int Quadric::Solve ( double * roots,
const double & a,
const double & b ) const

Solve the quadratic equation over a given interval.

This function store the sorted roots in an array and returns the number of roots.

Parameters
rootsThe array of roots.
a,bThe interval.

◆ Warp()

double Quadric::Warp ( const double & x)
inlinestatic

Unit interval warping function.

Remaps the unit interval into the unit interval by expanding the sides and compressing the center, keeping 1/2 mapped to 1/2.

Parameters
xReal in [0,1].

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Quadric & p )
friend

Overloaded output-stream operator.

Parameters
sStream.
pThe quadric.