Core 1.0
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
Cubic Class Reference

Cubic polynomials. More...

#include <cubic.h>

Public Member Functions

 Cubic ()
 Empty.
 
 Cubic (const double &, const double &, const double &, const double &)
 Creates a cubic. More...
 
 Cubic (const Quadric &)
 Creates a cubic given a quadric.
 
 ~Cubic ()
 Empty.
 
constexpr double & operator[] (int)
 Access class components.
 
constexpr double operator[] (int) const
 Overloaded.
 
int CheckDegree () const
 Check the degree of the cubic.
 
Cubic operator- () const
 Unary.
 
Cubicoperator+= (const Cubic &)
 Destructive sum of two cubics.
 
Cubicoperator-= (const Cubic &)
 Destructive difference of two cubics.
 
Cubicoperator*= (const double &)
 Scale a cubic by a double value.
 
Cubicoperator/= (const double &)
 Scale a cubic by a double value.
 
constexpr double operator() (const double &) const
 Evaluates the cubic. More...
 
constexpr double Derivative (const double &) const
 Computes the derivative of the cubic. More...
 
Quadric Prime () const
 Computes the first derivative of a cubic, which is a quadric.
 
Linear Second () const
 Computes the second derivative of a cubic, which is a linear polynomial.
 
int Solve (double *) const
 Solve the cubic equation. More...
 
int Solve (double *, const double &, const double &) const
 Search the roots of a polynomial equation over a given interval. More...
 
int SolveNormalized (double *) const
 Solve the normalized cubic equation, i.e., the highest coefficient is 1.0. More...
 
void Range (double &, double &, const double &=0.0, const double &=1.0) const
 Compute the range of values taken by the cubic over a given interval. More...
 
double K (const double &, const double &) const
 Compute the Lipschitz constant of the cubic. More...
 

Static Public Member Functions

static Cubic Compose (const Cubic &, const Linear &)
 Compose the cubic by a linear. More...
 
static Cubic Hermite (const double &, const double &, const double &, const double &)
 Creates an Hermite cubic polynomial. More...
 
static Cubic Bezier (const double &, const double &, const double &, const double &)
 Creates a cubic Bezier polynomial. More...
 
static Cubic Spline (const double &, const double &, const double &, const double &)
 Creates a cubic Spline polynomial. More...
 
static double Interpolation (const double &, const double &, const double &, const double &, const double &)
 Bicubic interpolation based on four values. More...
 
static double Smooth (const double &, const double &)
 Compute the value of a C2 smooth interpolating function (1-x/r)3. More...
 
static double SmoothCompact (const double &, const double &)
 Compactly supported smooth interpolating function. More...
 
static double SmoothCompact (const double &, const double &, const double &)
 Compactly supported smooth interpolating function. More...
 
static double Smooth (const double &)
 Compute the value of a C1 smooth interpolating function. More...
 
static double SmoothStep (const double &, const double &, const double &)
 Compute a smooth cubic step. More...
 
static double Gaussian (const double &, const double &, const double &)
 Compute a compactly supported Gaussian-like pulse. More...
 
static double GaussianThick (const double &, const double &, const double &, const double &)
 Compute a compactly supported Gaussian-like pulse with a thick plateau. More...
 
static double Sigmoid (const double &, const double &, const double &)
 Compute the value of a compactly supported sigmoid-shaped symmetric cubic. More...
 
static double Warp (const double &)
 Unit interval warping function. More...
 
static Cubic Bernstein (int)
 Creates a quadric Bernstein polynomial. More...
 
static double Bernstein (int, const double &)
 Compute the quadric Bernstein polynomial for a given value. More...
 

Protected Attributes

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

Friends

Cubic operator+ (const Cubic &, const Cubic &)
 Overloaded.
 
Cubic operator- (const Cubic &, const Cubic &)
 Overloaded.
 
Cubic operator* (const Cubic &, const double &)
 Multiply a cubic by a scalar value.
 
Cubic operator* (const double &, const Cubic &)
 Overloaded.
 
Cubic operator/ (const Cubic &, const double &)
 Overloaded.
 
Cubic operator* (const Quadric &, const Linear &)
 Multiply a quadric by a linear polynomial. More...
 
std::ostream & operator<< (std::ostream &, const Cubic &)
 Overloaded output-stream operator. More...
 

Detailed Description

Cubic polynomials.

Closed form expression of roots exist for such polynomials.

Constructors should provide the coefficients in descending order. Here is an example of how to code the cubic 2 x3-x+1:

Cubic p(2.0,0.0,-1.0,1.0);
Cubic polynomials.
Definition: cubic.h:8

How do I compute the interpolating smooth cubic (1-x/r)3 for values x within [0,r]?
A first solution is to use the Cubic class as follows:

double y=Cubic(-1.0/(r*r*r),3.0/(r*r),-3.0/r,1.0)(x)
Cubic()
Empty.
Definition: cubic.h:13

Cubic also implements some inline static member function such as :

inline double Cubic::Smooth(const double& x,const double& r)
{
return (1.0-x/r)*(1.0-x/r)*(1.0-x/r);
}
static double Smooth(const double &, const double &)
Compute the value of a C2 smooth interpolating function (1-x/r)3.
Definition: cubic.h:274

This function is more efficient if only one or two function calls are needed.

How do I create a Hermite cubic spline curve?
A simple way to do this is to use the static member function of the CubicCurve class, for example:

CubicCurve c=CubicCurve::Hermite(Vector(0,0,0),Vector(2,1,0),Vector(0,1,0),Vector(1,0,0));
Cubic curves.
Definition: curve.h:85
static CubicCurve Hermite(const Vector &, const Vector &, const Vector &, const Vector &)
Creates an Hermite cubic curve on interval [0,1] given vertex locations and tangent vectors (in that ...
Definition: curvecubic.cpp:184
double c[4]
Array of coefficients.
Definition: cubic.h:10
Vectors in three dimensions.
Definition: evector.h:21

Constructor & Destructor Documentation

◆ Cubic()

Cubic::Cubic ( const double &  a,
const double &  b,
const double &  c,
const double &  d 
)
inlineexplicit

Creates a cubic.

Coefficients start from the highest degree to the lowest.

Parameters
a,b,c,dCoefficients of the cubic a x3+b x2+c x+d.

Member Function Documentation

◆ Bernstein() [1/2]

Cubic Cubic::Bernstein ( int  p)
static

Creates a quadric Bernstein polynomial.

Parameters
pp-th polynomial.

◆ Bernstein() [2/2]

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

Compute the quadric Bernstein polynomial for a given value.

Parameters
pp-th polynomial.
xReal.

◆ Bezier()

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

Creates a cubic Bezier polynomial.

Interval parameterization is unit.

Parameters
a,b,c,dControl values.

◆ Compose()

Cubic Cubic::Compose ( const Cubic p,
const Linear q 
)
static

Compose the cubic by a linear.

This function computes p ( q(x) ), where p denotes the cubic and q the linear polynomial.

Parameters
pThe cubic.
qThe linear polynomial.

◆ Derivative()

constexpr double Cubic::Derivative ( const double &  x) const
inlineconstexpr

Computes the derivative of the cubic.

This function is more efficient than using Prime() and then evaluating the derivative for a given input value.

Parameters
xReal.

◆ Gaussian()

double Cubic::Gaussian ( const double &  c,
const double &  r,
const double &  x 
)
inlinestatic

Compute a compactly supported Gaussian-like pulse.

The function has C1 continuity.

See also
Quintic::Gaussian()
Parameters
cCenter.
rRadius.
xValue.

◆ GaussianThick()

double Cubic::GaussianThick ( const double &  c,
const double &  t,
const double &  r,
const double &  x 
)
inlinestatic

Compute a compactly supported Gaussian-like pulse with a thick plateau.

The function has C1 continuity.

See also
Quintic::GaussianThick()

The support has 2 ( r + t ) extent.

Parameters
cCenter.
t,rThickness (plateau) and radius.
xValue.

◆ Hermite()

Cubic Cubic::Hermite ( const double &  a,
const double &  b,
const double &  ta,
const double &  tb 
)
static

Creates an Hermite cubic polynomial.

Interval parameterization is unit.

Parameters
a,bValues for t=0 and t=1.
ta,tbDerivative values for t=0 and t=1.
See also
Math::Cubic()

◆ Interpolation()

double Cubic::Interpolation ( const double &  x,
const double &  a,
const double &  b,
const double &  c,
const double &  d 
)
static

Bicubic interpolation based on four values.

Parameters
a,b,c,dFour input values.
xInterpolant.
Author
Lois Paulin

◆ K()

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

Compute the Lipschitz constant of the cubic.

Parameters
a,bInterval.

◆ operator()()

constexpr double Cubic::operator() ( const double &  x) const
inlineconstexpr

Evaluates the cubic.

Parameters
xValue.

◆ Range()

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

Compute the range of values taken by the cubic over a given interval.

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.

◆ Sigmoid()

double Cubic::Sigmoid ( const double &  x,
const double &  r,
const double &  t 
)
static

Compute the value of a compactly supported sigmoid-shaped symmetric cubic.

The cubic was obtaied by solving the Hermite Cubic contraints: f(0)=0, f'(0)=1, f(R)=T and f'(R)=0. Coefficients are: a0=0, a1=1, a2=(3T-4R)/4R^2, a3=(R-T)/4R^3.

See also
Math::SigmoidQuadric
Parameters
xReal.
rRadius of influence.
tValue.

◆ Smooth() [1/2]

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

Compute the value of a C1 smooth interpolating function.

The cubic is defined as x2(3 - 2 x). Its first derivatives at 0.0 and 1.0 are 0.0.

The Lipschitz constant of the smooth quintic over [0,1] is λ=3/2.

Parameters
xArgument in [0,1].
See also
Quintic::Smooth(), Septic::Smooth()

◆ Smooth() [2/2]

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

Compute the value of a C2 smooth interpolating function (1-x/r)3.

It is possible to implement Wyvill's smoothing kernel by passing the squared distance to the skeleton and the squared radius to this function. For example, given a box skeleton:

Vector p(-2.0,3.0,5.0);
double d=Box(1.0).R(p); // Squared distance to a box
double r=4.0; // Radius;
double d=d>r*r?0.0:Cubic::Smooth(d,r*r); // Direct implementation of Wyvill's smoothing kernel
An axis aligned box.
Definition: box.h:23
double R(const Vector &) const
Computes the squared Euclidean distance between the box and a point.
Definition: box.h:256
See also
Smooth(const double&,const double&,const double&)
Parameters
xSquared distance.
rSquared radius.

◆ SmoothCompact() [1/2]

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

Compactly supported smooth interpolating function.

See also
Cubic::Smooth(const double&, const double&), Quadric::SmoothCompact()
Parameters
xSquared distance.
rSquared radius.

◆ SmoothCompact() [2/2]

double Cubic::SmoothCompact ( const double &  x,
const double &  ra,
const double &  rb 
)
inlinestatic

Compactly supported smooth interpolating function.

See also
Cubic::SmoothCompact(const double&,const double&)
Parameters
xDistance (not the squared distance).
ra,rbRadius interval.

◆ SmoothStep()

double Cubic::SmoothStep ( const double &  x,
const double &  a,
const double &  b 
)
inlinestatic

Compute a smooth cubic step.

The code is slightly more efficient than:

double y=Cubic::Smooth(Linear::Step(x,a,b));
static double Step(const double &, const double &, const double &)
Create a linear step.
Definition: linear.h:200
Parameters
a,bInterval values.
xInput value.
See also
Quintic::SmoothStep(), Septic::SmoothStep()

◆ Solve() [1/2]

int Cubic::Solve ( double *  y) const

Solve the cubic equation.

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

Parameters
yArray for storing the roots.

◆ Solve() [2/2]

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

Search the roots of a polynomial equation over a given interval.

Parameters
rootsArray for storing the roots.
a,bInterval limits.

◆ SolveNormalized()

int Cubic::SolveNormalized ( double *  y) const

Solve the normalized cubic equation, i.e., the highest coefficient is 1.0.

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

Parameters
yThe array of roots.

◆ Spline()

Cubic Cubic::Spline ( const double &  a,
const double &  b,
const double &  c,
const double &  d 
)
static

Creates a cubic Spline polynomial.

Interval parameterization is unit.

Parameters
a,b,c,dControl values.

◆ Warp()

double Cubic::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].

Friends And Related Function Documentation

◆ operator*

Cubic operator* ( const Quadric q,
const Linear l 
)
friend

Multiply a quadric by a linear polynomial.

Parameters
qQuadric.
lLinear.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Cubic c 
)
friend

Overloaded output-stream operator.

Parameters
sStream.
cCubic.