Skip to content

C++ interpolation class; linear, simple, exception-safe

Notifications You must be signed in to change notification settings

dhalonen/simpleInterpolation

Repository files navigation

simpleTools::interpolation

C++ interpolation class; simple, linear, exception-safe code that interpolates values in a table. Only a single header is needed.

To use, pass your table into class constructor & then use getY( x ). getY() computes the best match between any pair of points in the input table. If x is outside of the bounds of the table, getY() uses the 1st or last pair of points with the equation 'y = mx + b' to project the result.

simpleInterpolation is exception safe. If an over/underflow occurs, the C++ nan is returned.

Please refer to the unit tests. The chart below is used to support test cases. Interpolation Chart

Build instructions:

    g++ -std=c++11 simpleInterpolationTest.cpp

Successfully built and tested on Mac OSX, Raspberry Pi

Elaboration: https://davidhalonen.wordpress.com/2017/03/17/simple-tools-interpolation/

Alternatively, a "nearest neighbor" implementation has been added. Instead of a linear interpolation, it returns the 'y' value of the closest 'x' to the requested point. This is a very simple "interpolation".

About

C++ interpolation class; linear, simple, exception-safe

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages