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

A class for performing simple x-y-z bilinear interpolation. More...

#include <InterpolateBilinear.h>

Public Member Functions

int setData (const std::vector< double > &xValues, const std::vector< double > &yValues, const std::vector< std::vector< double > > &zValues)
 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 getMinY (double &minX) const
 Returns the minimum y-value from the stored data.
int getMaxY (double &maxX) const
 Returns the maximum y-value from the stored data.
int interpolate (double x, double y, double &zInterpolated)
 Performs bilinear interpolation given an (x, y) value pair.

Detailed Description

A class for performing simple x-y-z bilinear interpolation.

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

Methodology:

  • Given two sets of points x[i], y[i] sorted by increasing x and y.
  • To interpolate at a point pair (x', y'), find the four points: Q11 = (x1, y1) Q12 = (x1, y2) Q21 = (x2, y1) Q22 = (x2, y2) With known data points: z11 z12 z21 z22 such that: x1 <= x' < x2 and y1 <= y' < y2
  • Then compute:

    \‍[      z' = 1/((x2-x1)*(y2-y1)) * [z11(x2-x')(y2-y') + z12(x2-x')(y'-y1) + z21(x'-x1)(y2-y') + z22(x'-x1)(y'-y1)]
\‍]

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, y) below the minimum x/y or above the maximum x/y, a non-zero error code is returned.

Author: James Tabony james.nosp@m..tab.nosp@m.ony@a.nosp@m.ttx..nosp@m.tech

Member Function Documentation

◆ getMaxX()

int warptwin::InterpolateBilinear::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.

◆ getMaxY()

int warptwin::InterpolateBilinear::getMaxY ( double & maxX) const

Returns the maximum y-value from the stored data.

Parameters
[out]maxYThe maximum y-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::InterpolateBilinear::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.

◆ getMinY()

int warptwin::InterpolateBilinear::getMinY ( double & minX) const

Returns the minimum y-value from the stored data.

Parameters
[out]minYThe minimum y-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::InterpolateBilinear::interpolate ( double x,
double y,
double & zInterpolated )

Performs bilinear interpolation given an (x, y) value pair.

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

If x or y 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::InterpolateBilinear::setData ( const std::vector< double > & xValues,
const std::vector< double > & yValues,
const std::vector< std::vector< double > > & zValues )

Sets the data for the interpolator.

Parameters
xValuesA vector of x-values (must be sorted in ascending order).
yValuesA vector of y-values (must be sorted in ascending order).
zValuesA matrix of z-values whose ith row and jth col corresponds to the point x[i], y[j]
Returns
An integer error code (0 for success, non-zero for error).

This function replaces any previously stored data with the new x, y, and z values. It is required that xValues.size() == zValues.size() and yValues.size() == zValues[0].size(). It is alse required that xValues and yValues 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: