2

I have a control that's used as an exponent in a pow function. This changes the values in an ease in fashion. Is there a way to turn this into an ease out mathematically?

I know for example, ease in cubic is:

pow(t, 3)

but ease out cubic is:

(pow((t - 1), 3)) + 1

and ease out quart:

   float t = t2 - 1
   -(pow(t, 4) - 1)

So the formula changes quite a bit, and I need a generic way so I can use values like 4.2, 9.7, as the exponent etc.

Joan Venge
  • 315,713
  • 212
  • 479
  • 689

1 Answers1

3

For integer exponents this is called Hermite interpolation.


One can also interpret this task as an application of the chinese remainder theorem in polynomial rings

f(x) == 0 mod x^p
f(x) == 1 mod (x-1)^p

The solution has the form

f(x) = a(x)*x^p+b(x)*(x-1)^p  with  deg a(x) < p, deg b(x) < p.

Inserting into the second equations gives

a(x)*x^p == 1 mod (x-1)^p  <=>  a(y+1)*(y+1)^p == 1 mod y^p

which can be solved via binomial series, i.e., direct power series arithmetics without solving linear systems of equations,

a(y+1) = 1 - p*y + p*(p+1)/2*y^2 - p*(p+1)*(p+2)/2*y^3 +-... ...*y^(p-1)

For non-integer exponents, why would you want to do that?


Also look up "sigmoid functions".


Update

If continuity of derivatives is not so much a concern then for any positive a you can use c*x^a for 0<=x<=0.5 and 1-c*(1-x)^a for 0.5<=x<=1. To close the gap at x=0.5, the constant has to be chosen such that

1 = 2*c*0.5^a  <=>  c = 2^(a-1)

which can be implemented for 0<=x<=1 as

y = (0.5>x) ? 0.5*pow(2*x,a) : 1-0.5*pow(2*(1-x), a); 
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • Thanks alot, very helpful. Basically I want a normalized value to be modified via an exponent if wanted. But I also wanted to give the ease out version of it. Using exponents this way is useful but it's always a float in the apps I used. So in your first code, is it if mod(x, 2) == 0, etc? I tried this one: http://paste.ofcode.org/39dE6zyDnZ5xwWEu9viRszA – Joan Venge Apr 18 '15 at 14:10
  • I do not understand your `mod(x,2)` expression. I have added how you can get a power function go through (0.5,0,5) and make it symmetric relative to this point. – Lutz Lehmann Apr 18 '15 at 14:26
  • Thanks a lot, I meant like modulo with 2 to see if the exponent is odd or even. I thought that's what your first code did. – Joan Venge Apr 18 '15 at 14:49
  • I pasted some code here that shows the progression. If you notice the ease in always uses pow(value, exponent) while the ease out alternates between 2 different forms depending on if the value is odd or even. This why I thought maybe there is a way to generalize it. Someone told me to use matrices but not sure if it would help me. http://paste.ofcode.org/SCPe6pyZyAsnX7CuZtNZpq – Joan Venge Apr 18 '15 at 15:50
  • 1
    For the ease out you can always use `1-pow(1-t,exponent)`, this is always the same as your formulas. However, for `t=0.5`, or any other `t`, you get a gap between both functions, you can not switch between them without a jump. That is the reason for the scaling in my formulas. – Lutz Lehmann Apr 18 '15 at 16:26