Engauge Digitizer 2
Loading...
Searching...
No Matches
Spline.h
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "SplineCoeff.h"
8#include "SplinePair.h"
9#include <vector>
10
21class Spline
22{
23 public:
27 Spline(const std::vector<double> &t,
28 const std::vector<SplinePair> &xy);
29
30 virtual ~Spline();
31
35 int numIterations) const;
36
39 SplinePair interpolateCoeff (double t) const;
40
43 SplinePair interpolateControlPoints (double t) const;
44
46 SplinePair p1 (unsigned int i) const;
47
49 SplinePair p2 (unsigned int i) const;
50
51private:
52 Spline();
53
54 // Although coefficient interpolation works for successive t values not 1.0 apart, the control point interpolation
55 // does not so we check the increments. Note that the starting value is arbitrary. Removing this restriction will
56 // mean upgrading the code to allow arbitrary t increments
57 void checkTIncrements (const std::vector<double> &t) const;
58
59 void computeCoefficientsForIntervals (const std::vector<double> &t,
60 const std::vector<SplinePair> &xy);
61 void computeControlPointsForIntervals ();
62
63 // Coefficients a,b,c,d
64 std::vector<SplineCoeff> m_elements;
65
66 // Input times
67 std::vector<double> m_t;
68
69 // Input points
70 std::vector<SplinePair> m_xy;
71
72 // Control points for each interval
73 std::vector<SplinePair> m_p1;
74 std::vector<SplinePair> m_p2;
75};
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition SplinePair.h:12
Cubic interpolation given independent and dependent value vectors.
Definition Spline.h:22
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].
Definition Spline.cpp:170
SplinePair interpolateControlPoints(double t) const
Return interpolated y for specified x, for testing.
Definition Spline.cpp:140
SplinePair findSplinePairForFunctionX(double x, int numIterations) const
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x...
Definition Spline.cpp:104
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].
Definition Spline.cpp:163
SplinePair interpolateCoeff(double t) const
Return interpolated y for specified x.
Definition Spline.cpp:127