template<typename Value, typename InterpolationFunction = LinearInterpolation<Value>>
struct mc_trajectory::SequenceInterpolator< Value, InterpolationFunction >
Interpolate values in a timed sequence.
This class provides an efficient and generic way to perform interpolation within a sequence of (sorted) intervals expressed as pairs of (time, Value):
- ensures that values are sorted by strictly ascending time
- selects the appropriate interval corresponding to the desired computation time
- O(log n) when interpolating at an arbitrary time (binary search)
- O(1) in most cases when used sequentially (the current interval is cached)
- perform interpolation by calling the InterpolationFunction functor on this interval (default: linear interpolation). The time ratio within the current interval is computed as a normalized value between 0 and 1. See LinearInterpolation for example.
InterpolationFunction::operator(const Value &intervalStart, const Value &intervalEnd, double ratio)
Example:
auto values = std::vector<double, double>
{
{0., 0.},
{1., 100.},
{2., 200},
}
SequenceInterpolator<double> interp{
values};
interp.compute(0);
interp.compute(0.005);
interp.compute(1.2);
...
- Template Parameters
-
Value | Type of values to interpolate. It must meet the requirements of the InterpolationFunction (typically scalar-Value multiplication and Value-Value addition, e.g arithmetic types, Eigen::Vector, etc) |
InterpolationFunction | Functor for computing the interpolated value. |