This package supplies linear and spline interpolation functions.
lerp(src_val, dst_val, ratio)
(for scalar interpolation) interpolates src_val
and dst_val
with ratio
.
This will be replaced with std::lerp(src_val, dst_val, ratio)
in C++20
.
lerp(base_keys, base_values, query_keys)
(for vector interpolation) applies linear regression to each two continuous points whose x values arebase_keys
and whose y values are base_values
.
Then it calculates interpolated values on y-axis for query_keys
on x-axis.
spline(base_keys, base_values, query_keys)
(for vector interpolation) applies spline regression to each two continuous points whose x values arebase_keys
and whose y values are base_values
.
Then it calculates interpolated values on y-axis for query_keys
on x-axis.
We evaluated calculation cost of spline interpolation for 100 points, and adopted the best one which is tridiagonal matrix algorithm.
Methods except for tridiagonal matrix algorithm exists in spline_interpolation
package, which has been removed from Autoware.
Method | Calculation time |
---|---|
Tridiagonal Matrix Algorithm | 0.007 [ms] |
Preconditioned Conjugate Gradient | 0.024 [ms] |
Successive Over-Relaxation | 0.074 [ms] |
Assuming that the size of base_keys
(base_values
(
Constraints on spline interpolation are as follows.
The number of constraints is
$$ \begin{align} Y_i (x_i) & = y_i \ \ \ (i = 0, \dots, N-1) \ Y_i (x_{i+1}) & = y_{i+1} \ \ \ (i = 0, \dots, N-1) \ Y'i (x{i+1}) & = Y'{i+1} (x{i+1}) \ \ \ (i = 0, \dots, N-2) \ Y''i (x{i+1}) & = Y''{i+1} (x{i+1}) \ \ \ (i = 0, \dots, N-2) \ Y''0 (x_0) & = 0 \ Y''{N-1} (x_N) & = 0 \end{align} $$
According to this article, spline interpolation is formulated as the following linear equation.
where
The coefficient matrix of this linear equation is tridiagonal matrix. Therefore, it can be solve with tridiagonal matrix algorithm, which can solve linear equations without gradient descent methods.
Solving this linear equation with tridiagonal matrix algorithm, we can calculate coefficients of spline interpolation as follows.
We solve tridiagonal linear equation according to this article where variables of linear equation are expressed as follows in the implementation.