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

Linear polynomials. More...

#include <linear.h>

Public Member Functions

 Linear ()
 Empty.
 
 Linear (const double &, const double &)
 Creates a linear function. More...
 
 Linear (const double &)
 Creates a constant function. More...
 
 ~Linear ()
 Empty.
 
constexpr double & operator[] (int)
 Access class components.
 
constexpr double operator[] (int) const
 Overloaded.
 
Linear operator- () const
 Unary.
 
Linearoperator+= (const Linear &)
 Destructive sum of two linear polynomials.
 
Linearoperator-= (const Linear &)
 Destructive difference of two linear polynomials.
 
Linearoperator*= (const double &)
 Scale a linear polynomial by a double value.
 
Linearoperator/= (const double &)
 Scales a linear polynomial by a double value.
 
constexpr double operator() (const double &) const
 Evaluates the linear function. More...
 
int Solve (double &) const
 Solve linear equations. More...
 
int Solve (double &, const double &, const double &) const
 Search the roots of a linear equation over a given interval. More...
 
void Range (double &, double &, const double &=0.0, const double &=1.0) const
 This function computes the range of values taken by a Linear over a given interval. More...
 

Static Public Member Functions

static double Step (const double &, const double &, const double &)
 Create a linear step. More...
 
static double Step (const double &, const double &, const double &, const double &, const double &)
 Create a linear step. More...
 
static double Affine (const double &, const double &, const double &)
 Create the linear part of a linear step. More...
 
static double Solve (const double &, const double &, const double &, const double &)
 Compute the root of a linear function such that f(a)=va and f(b)=vb. More...
 
static double SolveAlpha (const double &, const double &, const double &, const double &)
 Compute the root of a linear function. More...
 

Protected Attributes

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

Friends

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

Detailed Description

Linear polynomials.

When using constructors, the coefficients are given in descending order:

Linear p(-1.0,1.0); // Linear polynomial -x + 1
Linear polynomials.
Definition: linear.h:8

Constructor & Destructor Documentation

◆ Linear() [1/2]

Linear::Linear ( const double &  a,
const double &  b 
)
inlineexplicit

Creates a linear function.

The function is defined as f(x) = a x + b.

Parameters
a,bCoefficients.

◆ Linear() [2/2]

Linear::Linear ( const double &  a)
inlineexplicit

Creates a constant function.

Parameters
aConstant.

Member Function Documentation

◆ Affine()

double Linear::Affine ( const double &  x,
const double &  a,
const double &  b 
)
inlinestatic

Create the linear part of a linear step.

This function does not test limits.

Parameters
xValue
a,bInterval values.
Returns
Real in unit inverval.
See also
Linear::Step

◆ operator()()

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

Evaluates the linear function.

Parameters
xArgument.

◆ Range()

void Linear::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 Linear over a given interval.

Parameters
a,bInterval.
x,yReturned range.

◆ Solve() [1/3]

double Linear::Solve ( const double &  a,
const double &  b,
const double &  va,
const double &  vb 
)
inlinestatic

Compute the root of a linear function such that f(a)=va and f(b)=vb.

Assuming that the root exists, this function reads easier than the following code, and avoids constructor and parameter computation.

double t;
int n=Linear((vb-va)/(b-a),b*va+a*vb).Solve(t);
Linear()
Empty.
Definition: linear.h:13
See also
Vector::Solve(const Vector& a, const Vector& b, const double&, const double&);

◆ Solve() [2/3]

int Linear::Solve ( double &  x) const

Solve linear equations.

This function store the root (ifit exists) in a double and returns the number of roots.

Parameters
xSolution.

◆ Solve() [3/3]

int Linear::Solve ( double &  x,
const double &  a,
const double &  b 
) const

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

Parameters
xSolution.
a,bInterval.

◆ SolveAlpha()

double Linear::SolveAlpha ( const double &  a,
const double &  b,
const double &  va,
const double &  vb 
)
static

Compute the root of a linear function.

The linear function satisfies the constraints: f(a)=va and f(b)=vb; the function returns an interpolant t such that the root satisties r=(1-t) a+t b.

See also
Linear::Solve(const Vector& a, const Vector& b, const double&, const double&);

◆ Step() [1/2]

double Linear::Step ( const double &  x,
const double &  a,
const double &  b 
)
inlinestatic

Create a linear step.

Parameters
xValue
a,bInterval values.
Returns
Real in unit inverval.
See also
Cubic::SmoothStep, Quintic::SmoothStep

◆ Step() [2/2]

double Linear::Step ( const double &  x,
const double &  a,
const double &  b,
const double &  ya,
const double &  yb 
)
inlinestatic

Create a linear step.

This function is the same as coding:

double y=Math::Lerp(ya,yb,Linear::Step(x,a,b));
static double Step(const double &, const double &, const double &)
Create a linear step.
Definition: linear.h:200
static double Lerp(const double &, const double &, const double &)
Linear interpolation.
Definition: mathematics.h:469
Parameters
xValue
a,bInterval values.
ya,ybOutput interval values.
See also
Cubic::SmoothStep, Quintic::SmoothStep

Friends And Related Function Documentation

◆ operator<<

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

Overloaded output-stream operator.

Parameters
sStream.
pLinear polynomial.