While strictly related to a programming project of mine, the problem in itself boils down to a math problem, as I am not sure which steps to take to produce the results i need.
I have an input value (floating point) that ranges from -1 and +1.
This needs to be translated into an output value based on an arbitrary range. Let's call the output-range Omin-Omid-Omax, consisting of arbitrary values.
And yes, the word Range might not be the best one, seeing as the output range consists of three points. The reason for this is that the midpoint isn't necessarily the average of min and max, i.e. if one were to plot a curve based on the input and the desired output, the curve wouldn't be linear. The reason for Omid is to give a value that an input of 0 should result in.
How would i go about finding the corresponding value in Omin-Omid-Omax based on the input value?
PS: The Omin-Omid-Omax can be considered to be two linear ranges (Omin-Omid and Omid-Omax)
Hopefully this question makes sense. As you've probably figured, math is not my strongest suit, so I just hope that it's understandable.
You can use Spline Interpolation, which yields a continuous 3rd-degree polynomial function.
The function is guaranteed to be twice-differentiable (
f,f'andf''are viable functions).This attribute will effectively give a "smooth appearance" to the original function.
Here is a piece of C code for any given number of points $(x_0,y_0),(x_1,y_1),...,(x_N,y_N)$:
Here is a piece of Python code for any given number of points $(x_0,y_0),(x_1,y_1),...,(x_N,y_N)$:
Please note that the two pieces of code above assume $x_0 < x_1 < ... < x_N$.