Let's assume you are in 2D space and you have a set of fix points
FIX_POINTS = [(x1, y1), (x2, y2)]. I want to interpolate the
y value for a given
x value using the provided points as fix points for a piecewise linear interpolation.
Caveat: The x-axis is cyclic, so it wraps around at a certain known value.
I'm searching a neat algorithm (or way to write this down) which can do this interpolation, so take an x value on the cyclic x-axes and compute the y- value using piecewise linear interpolation.
FIX_POINTS = [(10, 50), (90, 100)], and a "cyclic interval" (so the value at which the x axes wraps) of
100, the interpolation would lead to the following results:
interpolation(10) = 50 # No interpolation necessary, directly on fix points interpolation(90) = 100 # Same interpolation(50) = 75 # Normal Interpolation interpolation(0) = 75 # Wrap around interpolation interpolation(1) = 72.5 # Same interpolation(99) = 77.5 # Same
I'm not too curious in the actual programming, I'm searching for a way to write this down nicely. Maybe there is even an existing implementation for this? I'm having troubles asking google for the lack of search terms.
I implemented it myself, but it got a lot of code, so I'm in search of something simpler: https://gist.github.com/theomega/9782be548fd452e1f1469757387b35e4 . This implementation also is far from optimal on the computational side (scanning over the array).
I'm not sure if this is the stack exchange for this. Feel free to point me in a different direction.