WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
clockwerk::Interpolator Class Reference

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

#include <Interpolator.h>

Public Member Functions

int16 setData (const floating_point *x_array_ptr, const floating_point *y_array_ptr, uint32 size)
 Sets the data for the interpolator.
floating_point getMinX () const
 Returns the minimum x-value from the stored data.
floating_point getMaxX () const
 Returns the maximum x-value from the stored data.
int16 interpolate (floating_point x, floating_point &y_out)
 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])
\‍]

Member Function Documentation

◆ getMaxX()

floating_point clockwerk::Interpolator::getMaxX ( ) const

Returns the maximum x-value from the stored data.

Returns
The maximum x value
Note
Returns float_max if x array ptr is not set

◆ getMinX()

floating_point clockwerk::Interpolator::getMinX ( ) const

Returns the minimum x-value from the stored data.

Returns
The minimum x value
Note
Returns float_min if x array ptr is not set

◆ interpolate()

int16 clockwerk::Interpolator::interpolate ( floating_point x,
floating_point & y_out )

Performs linear interpolation given an x-value.

Parameters
[in]xThe x-value for which to interpolate.
[out]y_outThe 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()

int16 clockwerk::Interpolator::setData ( const floating_point * x_array_ptr,
const floating_point * y_array_ptr,
uint32 size )

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:
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/utils/Interpolator.h
  • /Users/mickey/Documents/Projects/warptwin/warpos/clockwerk/src/utils/Interpolator.cpp