ACF $AcfVersion:0$
Public Member Functions | List of all members
imath::CLinearInterpolator Class Reference

Implementation of a linear interpolator for piecewise linear function approximation. More...

#include <CLinearInterpolator.h>

Inheritance diagram for imath::CLinearInterpolator:
imath::ISampledFunctionInterpolator imath::TIMathFunction< Argument, Result > istd::IPolymorphic

Public Member Functions

 CLinearInterpolator ()
 
 CLinearInterpolator (double *positions, double *values, int nodesCount, bool isExtrapolationEnabled=false)
 
void SetNodes (double *positions, double *values, int nodesCount)
 
virtual bool InitFromFunction (const ISampledFunction &function) override
 Initialize interpolator based on a sample function.
 
virtual bool GetValueAt (const double &argument, double &result) const override
 
virtual double GetValueAt (const double &argument) const override
 
- Public Member Functions inherited from imath::TIMathFunction< Argument, Result >
virtual bool GetValueAt (const Argument &argument, Result &result) const =0
 Get function value for specified argument value.
 
virtual Result GetValueAt (const Argument &argument) const =0
 Get function value for specified argument value.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Additional Inherited Members

- Public Types inherited from imath::TIMathFunction< Argument, Result >
typedef Argument ArgumentType
 
typedef Result ResultType
 

Detailed Description

Implementation of a linear interpolator for piecewise linear function approximation.

Purpose

CLinearInterpolator provides simple and efficient piecewise linear interpolation through a set of data points. It creates straight line segments between consecutive points, offering exact reproduction of linear functions and predictable behavior for all input data. Optional extrapolation extends the function beyond the defined domain using the slopes of the first and last segments.

Characteristics

Usage Examples

// Create interpolator with extrapolation disabled (default)
double positions[] = {0.0, 1.0, 2.0, 3.0};
double values[] = {0.0, 2.0, 1.5, 3.0};
imath::CLinearInterpolator interp1(positions, values, 4, false);
// Query inside domain
double result;
if (interp1.GetValueAt(1.5, result)) {
// result ~ 1.75 (linear interpolation between 2.0 and 1.5)
}
// Query outside domain (no extrapolation)
double value1 = interp1.GetValueAt(-1.0); // Returns 0.0 (first value)
double value2 = interp1.GetValueAt(5.0); // Returns 3.0 (last value)
// Create interpolator with extrapolation enabled
imath::CLinearInterpolator interp2(positions, values, 4, true);
double value3 = interp2.GetValueAt(-1.0); // Extrapolates using first segment slope
double value4 = interp2.GetValueAt(5.0); // Extrapolates using last segment slope
// Initialize from ISampledFunction
// interp1.InitFromFunction(sampledFunction);
Implementation of a linear interpolator for piecewise linear function approximation.

When to Use

Use linear interpolation when:

Consider other methods when:

See also
imath::CAkimaInterpolator, imath::ISampledFunctionInterpolator

Definition at line 76 of file CLinearInterpolator.h.

Constructor & Destructor Documentation

◆ CLinearInterpolator() [1/2]

imath::CLinearInterpolator::CLinearInterpolator ( )

◆ CLinearInterpolator() [2/2]

imath::CLinearInterpolator::CLinearInterpolator ( double *  positions,
double *  values,
int  nodesCount,
bool  isExtrapolationEnabled = false 
)
Parameters
isExtrapolationEnabledIf enabled, the values will be extrapolatied also outside of defined domain, otherwise returned value for argument outside[positionMin, positionMax] is the last value.

Member Function Documentation

◆ GetValueAt() [1/2]

virtual double imath::CLinearInterpolator::GetValueAt ( const double &  argument) const
overridevirtual

◆ GetValueAt() [2/2]

virtual bool imath::CLinearInterpolator::GetValueAt ( const double &  argument,
double &  result 
) const
overridevirtual

◆ InitFromFunction()

virtual bool imath::CLinearInterpolator::InitFromFunction ( const ISampledFunction function)
overridevirtual

Initialize interpolator based on a sample function.

Implements imath::ISampledFunctionInterpolator.

◆ SetNodes()

void imath::CLinearInterpolator::SetNodes ( double *  positions,
double *  values,
int  nodesCount 
)

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