1 #ifndef MSP_INTERPOLATE_LINEARSPLINE_H_
2 #define MSP_INTERPOLATE_LINEARSPLINE_H_
8 namespace Interpolate {
11 A very simple type of spline. It interpolates the value linearly between
14 template<typename T, unsigned N = 1>
15 class LinearSpline: public Spline<T, 1, N>
18 using typename Spline<T, 1, N>::Value;
19 using typename Spline<T, 1, N>::Knot;
21 LinearSpline(const std::vector<Knot> &k):
22 Spline<T, 1, N>(k.front())
24 typedef SplineValue<T, N> SV;
26 this->reserve(k.size()-1);
27 for(unsigned i=1; i<k.size(); ++i)
29 T dx = k[i].x-k[i-1].x;
30 Value slope = (k[i].y-k[i-1].y)/dx;
31 Polynomial<T, 1> p[N];
32 for(unsigned j=0; j<N; ++j)
33 p[j] = Polynomial<T, 1>(LinAl::Vector<T, 2>(SV::get(slope, j), SV::get(k[i-1].y, j)-k[i-1].x*SV::get(slope, j)));
34 this->add_segment(p, k[i].x);
39 } // namespace Interpolate