Engauge Digitizer 2
|
Cubic interpolation given independent and dependent value vectors. More...
#include <Spline.h>
Public Member Functions | |
Spline (const std::vector< double > &t, const std::vector< SplinePair > &xy, SplineTCheck splineTCheck=SPLINE_ENABLE_T_CHECK) | |
Initialize spline with independent (t) and dependent (x and y) value vectors. | |
virtual | ~Spline () |
void | computeUntranslatedCoefficients (double aTranslated, double bTranslated, double cTranslated, double dTranslated, double tI, double &aUntranslated, double &bUntranslated, double &cUntranslated, double &dUntranslated) const |
From coefficients in xy=d*(t-ti)^3+c*(t-ti)^2+b*(t-ti)+a we compute and return the coefficients in xy=d* t ^3+c* t ^2+b* t +a. | |
SplinePair | findSplinePairForFunctionX (double x, int numIterations) const |
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x value. | |
SplinePair | interpolateCoeff (double t) const |
Return interpolated y for specified x. | |
SplinePair | interpolateControlPoints (double t) const |
Return interpolated y for specified x, for testing. | |
SplinePair | p1 (unsigned int i) const |
Bezier p1 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1]. | |
SplinePair | p2 (unsigned int i) const |
Bezier p2 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1]. |
Friends | |
class | TestSpline |
For unit testing. |
Cubic interpolation given independent and dependent value vectors.
X is handled as a dependent variable based on the unitless independent parameter t so curves are not restricted to x(i)!=x(i+1).
This class has two modes that can be run side by side:
Spline::Spline | ( | const std::vector< double > & | t, |
const std::vector< SplinePair > & | xy, | ||
SplineTCheck | splineTCheck = SPLINE_ENABLE_T_CHECK ) |
Initialize spline with independent (t) and dependent (x and y) value vectors.
Besides initializing the a,b,c,d coefficients for each interval, this constructor initializes bezier points (P1 and P2) for each interval, where P0 and P3 are the start and end points for each interval.
Definition at line 13 of file Spline.cpp.
|
virtual |
Definition at line 28 of file Spline.cpp.
void Spline::computeUntranslatedCoefficients | ( | double | aTranslated, |
double | bTranslated, | ||
double | cTranslated, | ||
double | dTranslated, | ||
double | tI, | ||
double & | aUntranslated, | ||
double & | bUntranslated, | ||
double & | cUntranslated, | ||
double & | dUntranslated ) const |
From coefficients in xy=d*(t-ti)^3+c*(t-ti)^2+b*(t-ti)+a we compute and return the coefficients in xy=d* t ^3+c* t ^2+b* t +a.
Definition at line 145 of file Spline.cpp.
SplinePair Spline::findSplinePairForFunctionX | ( | double | x, |
int | numIterations ) const |
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x value.
This assumes the curve is a function since otherwise there is the potential for multiple solutions
Definition at line 172 of file Spline.cpp.
SplinePair Spline::interpolateCoeff | ( | double | t | ) | const |
Return interpolated y for specified x.
The appropriate interval is selected from the entire set of piecewise-defined intervals, then the corresponding a,b,c,d coefficients are applied
Definition at line 233 of file Spline.cpp.
SplinePair Spline::interpolateControlPoints | ( | double | t | ) | const |
Return interpolated y for specified x, for testing.
This uses the bezier points. If the t values are not separated by +1 consistently then this algorithm will probably need additional effort to work right
Definition at line 246 of file Spline.cpp.
SplinePair Spline::p1 | ( | unsigned int | i | ) | const |
Bezier p1 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
Definition at line 269 of file Spline.cpp.
SplinePair Spline::p2 | ( | unsigned int | i | ) | const |
Bezier p2 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
Definition at line 276 of file Spline.cpp.
|
friend |