Celeritas
0.5.0-56+6b053cd
|
Interpolate, with either linear or log in x and y. More...
#include <Interpolator.hh>
Public Types | |
Type aliases | |
using | real_type = T |
using | Point = Array< T, 2 > |
Public Member Functions | |
CELER_FUNCTION | Interpolator (Point left, Point right) |
Construct with left and right values for x and y. | |
CELER_FUNCTION real_type | operator() (real_type x) const |
Interpolate linearly on the transformed type. | |
Interpolate, with either linear or log in x and y.
XI | Transform to apply to X coordinate |
YI | Transform to apply to Y coordinate |
T | Floating point type |
The inputs are given as two (x,y) pairs. The same two pairs can be used to interpolate successively with this functor.
Interpolation on the transformed coordinates is the solution for \( y \) in
\[ \frac{f_y(y) - f_y(y_l)}{f_y(y_r) - f_y(y_l)} = \frac{f_x(x) - f_x(x_l)}{f_x(x_r) - f_x(x_l)} \]
where \( f_d(v) = v \) for linear interpolation on the \( d \) axis and \( f_d(v) = \log v \) for log interpolation.
Solving for \(y\), the interpolation can be rewritten to minimize transcendatal operations and efficiently perform multiple interpolations over the same point range:
\[ y = f^{-1}_y \left( f_y(y_l) + \frac{ p_y(n_y(y_l), y_r) }{ p_x(n_x(x_l), x_r)} \times p_x(n_x(x_l), x) \right) \]
where transformed addition is \(p_y(y_1, y_2) \equiv f_y(y_1) + f_y(y_2)\) , transformed negation is \(n_y(y_1) \equiv f^{-1}_y( - f_y(y_1) )\) and \( f_y(y) = y \) for linear interpolation in y and \( f_y(y) = \log y \) for log interpolation in y.
Instantiating the interpolator precalculates the transformed intercept and slope terms, as well as the negated x-left term. At each evaluation of the instantiated Interpolator, only the inverse-transform and add-transformed operation need be applied.