0.4.1
Loading...
Searching...
No Matches
NAV::CubicSpline< Scalar > Class Template Reference

Cubic Spline class. More...

Data Structures

class  BandMatrix
 Sparse matrix whose non-zero entries are confined to a diagonal band, comprising the main diagonal and zero or more diagonals on either side. More...
 
struct  BoundaryCondition
 Boundary conditions for the spline end-points. More...
 

Public Member Functions

 CubicSpline ()=default
 Default Constructor.
 
 CubicSpline (const std::vector< Scalar > &X, const std::vector< Scalar > &Y, BoundaryCondition leftBoundaryCondition={ BoundaryCondition::SecondDerivative, 0.0 }, BoundaryCondition rightBoundaryCondition={ BoundaryCondition::SecondDerivative, 0.0 })
 Constructor.
 
Scalar derivative (size_t order, Scalar x) const
 Calculates the derivative of the spline.
 
Scalar operator() (Scalar x) const
 Interpolates or extrapolates a value on the spline.
 
void setBoundaries (BoundaryCondition leftBoundaryCondition, BoundaryCondition rightBoundaryCondition)
 Set the boundaries conditions. Has to be called before setPoints.
 
void setPoints (const std::vector< Scalar > &x, const std::vector< Scalar > &y)
 Set the points/knots of the spline and calculate the spline coefficients.
 
size_t size () const noexcept
 Returns the size of the spline vector.
 

Private Member Functions

size_t findClosestIdx (Scalar x) const
 Finds the closest index so that vals_x[idx] <= x (return 0 if x < vals_x[0])
 

Private Attributes

BoundaryCondition boundaryConditionLeft
 Boundary condition for the left knot.
 
BoundaryCondition boundaryConditionRight
 Boundary condition for the right knot.
 
std::vector< Scalar > coef_b
 Spline coefficients b.
 
std::vector< Scalar > coef_c
 Spline coefficients c.
 
Scalar coef_c0
 Spline coefficient c0 for left extrapolation.
 
std::vector< Scalar > coef_d
 Spline coefficients d.
 
std::vector< Scalar > vals_x
 x coordinates of the knots
 
std::vector< Scalar > vals_y
 y coordinates of the knots
 

Detailed Description

template<typename Scalar>
class NAV::CubicSpline< Scalar >

Cubic Spline class.

Definition at line 34 of file CubicSpline.hpp.

Constructor & Destructor Documentation

◆ CubicSpline() [1/2]

template<typename Scalar>
NAV::CubicSpline< Scalar >::CubicSpline ( )
default

Default Constructor.

◆ CubicSpline() [2/2]

template<typename Scalar>
NAV::CubicSpline< Scalar >::CubicSpline ( const std::vector< Scalar > & X,
const std::vector< Scalar > & Y,
BoundaryCondition leftBoundaryCondition = BoundaryCondition::SecondDerivative, 0.0 },
BoundaryCondition rightBoundaryCondition = BoundaryCondition::SecondDerivative, 0.0 } )
inline

Constructor.

Parameters
[in]XList of x coordinates for the spline points/knots
[in]YList of y coordinates for the spline points/knots
[in]leftBoundaryConditionBoundary condition for the start knot
[in]rightBoundaryConditionBoundary condition for the end knot

Definition at line 59 of file CubicSpline.hpp.

Member Function Documentation

◆ derivative()

template<typename Scalar>
Scalar NAV::CubicSpline< Scalar >::derivative ( size_t order,
Scalar x ) const
inlinenodiscard

Calculates the derivative of the spline.

Parameters
[in]orderOrder of the derivative to calculate (<= 3)
[in]xX coordinate to calculate the derivative for
Returns
The derivative of y up to the given order

Definition at line 205 of file CubicSpline.hpp.

◆ findClosestIdx()

template<typename Scalar>
size_t NAV::CubicSpline< Scalar >::findClosestIdx ( Scalar x) const
inlinenodiscardprivate

Finds the closest index so that vals_x[idx] <= x (return 0 if x < vals_x[0])

Parameters
[in]xX coordinate to search the closest knot to
Returns
Index of a knot closest to the x coordinate given

Definition at line 265 of file CubicSpline.hpp.

◆ operator()()

template<typename Scalar>
Scalar NAV::CubicSpline< Scalar >::operator() ( Scalar x) const
inlinenodiscard

Interpolates or extrapolates a value on the spline.

Parameters
[in]xX coordinate to inter-/extrapolate the value for
Returns
The y coordinate

Definition at line 182 of file CubicSpline.hpp.

◆ setBoundaries()

template<typename Scalar>
void NAV::CubicSpline< Scalar >::setBoundaries ( BoundaryCondition leftBoundaryCondition,
BoundaryCondition rightBoundaryCondition )
inline

Set the boundaries conditions. Has to be called before setPoints.

Parameters
[in]leftBoundaryConditionBoundary condition for the start knot
[in]rightBoundaryConditionBoundary condition for the end knot

Definition at line 70 of file CubicSpline.hpp.

◆ setPoints()

template<typename Scalar>
void NAV::CubicSpline< Scalar >::setPoints ( const std::vector< Scalar > & x,
const std::vector< Scalar > & y )
inline

Set the points/knots of the spline and calculate the spline coefficients.

Parameters
[in]xList of x coordinates of the points
[in]yList of y coordinates of the points

Definition at line 79 of file CubicSpline.hpp.

◆ size()

template<typename Scalar>
size_t NAV::CubicSpline< Scalar >::size ( ) const
inlinenodiscardnoexcept

Returns the size of the spline vector.

Definition at line 174 of file CubicSpline.hpp.

Field Documentation

◆ boundaryConditionLeft

template<typename Scalar>
BoundaryCondition NAV::CubicSpline< Scalar >::boundaryConditionLeft
private

Boundary condition for the left knot.

Definition at line 259 of file CubicSpline.hpp.

◆ boundaryConditionRight

template<typename Scalar>
BoundaryCondition NAV::CubicSpline< Scalar >::boundaryConditionRight
private

Boundary condition for the right knot.

Definition at line 260 of file CubicSpline.hpp.

◆ coef_b

template<typename Scalar>
std::vector<Scalar> NAV::CubicSpline< Scalar >::coef_b
private

Spline coefficients b.

Definition at line 254 of file CubicSpline.hpp.

◆ coef_c

template<typename Scalar>
std::vector<Scalar> NAV::CubicSpline< Scalar >::coef_c
private

Spline coefficients c.

Definition at line 255 of file CubicSpline.hpp.

◆ coef_c0

template<typename Scalar>
Scalar NAV::CubicSpline< Scalar >::coef_c0
private

Spline coefficient c0 for left extrapolation.

Definition at line 257 of file CubicSpline.hpp.

◆ coef_d

template<typename Scalar>
std::vector<Scalar> NAV::CubicSpline< Scalar >::coef_d
private

Spline coefficients d.

Definition at line 256 of file CubicSpline.hpp.

◆ vals_x

template<typename Scalar>
std::vector<Scalar> NAV::CubicSpline< Scalar >::vals_x
private

x coordinates of the knots

Definition at line 252 of file CubicSpline.hpp.

◆ vals_y

template<typename Scalar>
std::vector<Scalar> NAV::CubicSpline< Scalar >::vals_y
private

y coordinates of the knots

Definition at line 253 of file CubicSpline.hpp.


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