Generate easing function from hash table/value pairs

224 Views Asked by At

I have a hash-table/value-pair list consisting of, what I call, linear control value paired with curved/eased real values.

Something like this:

  • 0 = 0
  • 1 = 0.0010000000000000002
  • 2 = 0.008000000000000002
  • 3 = 0.027
  • 4 = 0.06400000000000002
  • 5 = 0.125
  • 6 = 0.216
  • 7 = 0.3429999999999999
  • 8 = 0.5120000000000001
  • 9 = 0.7290000000000001
  • 10 = 1

In this example I already know the curve to be a simple Math Power of 3.

In my real scenario, my control values range from 0-65534 and my real values go from 1-1000. I have a huge table describing every single control value from 0-65534. And with this table I have no idea how the easing/curving function is constructed.

Question boils down to:

Is it possible to use this table of data to somehow figure out an easing function that would let me supply only the control value and in return get my eased real value? For example I could input 5 and get 0.125 which happens to be the absolute middle of the value table, but value-wise in the real value list very low, due to the curving.

If it's impossible to figure out exactly with mathematics and programming I would absolutely consider finding an approximate, but not exact, solution as well.

1

There are 1 best solutions below

1
On BEST ANSWER

What you're asking is to fit a simple function to your data points. The quickest and simplest way to do this is to use the "Trend Line" function in Excel. More info about this in this answer.

If the input values were generated from some simple equation, it's likely that Excel will be able to rediscover this equation, and the solution will be exact (to within the limits of floating point arithmetic, anyway). If not, the solution will be an approximation. You could get an exact interpolation of all your 65535 values if you used a polynomial of degree 65534, but that would be goofy.

In the example you gave, Excel will correctly discover the equation $y = 0.001x^3$.

If you have some preconceived notion of what type of function you want, you can tell Excel. If Excel doesn't support this type, then you'll probably have to write some least-squares fitting code yourself.