WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
warptwin::Interpolate2D Class Reference

A class for performing simple x-y linear interpolation. More...

#include <Interpolate2D.h>

Public Member Functions

int setData (const std::vector< double > &xValues, const std::vector< double > &yValues)
 Sets the data for the interpolator.
int getMinX (double &minX) const
 Returns the minimum x-value from the stored data.
int getMaxX (double &maxX) const
 Returns the maximum x-value from the stored data.
int interpolate (double x, double &yInterpolated)
 Performs linear interpolation given an x-value.

Detailed Description

A class for performing simple x-y linear interpolation.

This class allows you to store tabulated x and y values, and then to compute interpolated y values for any x within the bounds of the stored data. The linear interpolation is performed between successive data points.

Methodology:

  • Given a set of points (x[i], y[i]) sorted by increasing x.
  • To interpolate at a value x', find the interval [x[i], x[i+1]] such that x[i] <= x' <= x[i+1].
  • Then compute:

    \‍[      y' = y[i] + \frac{(y[i+1] - y[i])}{(x[i+1] - x[i])} (x' - x[i])
\‍]

Error Handling:

  • The class returns integer error codes rather than using exceptions.
    • 0 indicates success
    • Any non-zero integer indicates an error
  • If interpolation is requested for x' below the minimum x or above the maximum x, a non-zero error code is returned.

Member Function Documentation

◆ getMaxX()

int warptwin::Interpolate2D::getMaxX ( double & maxX) const

Returns the maximum x-value from the stored data.

Parameters
[out]maxXThe maximum x-value will be written here if the function succeeds.
Returns
Integer error code (0 for success, non-zero for error).

This function returns an error if there is no data stored.

◆ getMinX()

int warptwin::Interpolate2D::getMinX ( double & minX) const

Returns the minimum x-value from the stored data.

Parameters
[out]minXThe minimum x-value will be written here if the function succeeds.
Returns
Integer error code (0 for success, non-zero for error).

This function returns an error if there is no data stored.

◆ interpolate()

int warptwin::Interpolate2D::interpolate ( double x,
double & yInterpolated )

Performs linear interpolation given an x-value.

Parameters
[in]xThe x-value for which to interpolate.
[out]yInterpolatedThe interpolated y-value will be written here if the function succeeds.
Returns
Integer error code (0 for success, non-zero for error).

If x is out of the bounds of the stored table, this function returns a non-zero error code. If there are not enough points to perform interpolation, it returns a non-zero error code as well.

◆ setData()

int warptwin::Interpolate2D::setData ( const std::vector< double > & xValues,
const std::vector< double > & yValues )

Sets the data for the interpolator.

Parameters
xValuesA vector of x-values (must be sorted in ascending order).
yValuesA vector of y-values corresponding to xValues.
Returns
An integer error code (0 for success, non-zero for error).

This function replaces any previously stored data with the new x and y values. It is required that xValues.size() == yValues.size() and that xValues is sorted in ascending order. If these conditions are not met, a non-zero error code is returned.


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