12
$\begingroup$

I am trying to create a nice ease-in-out function that given values from 0 - 1 produces an output of 0 - 1 which accelerates slowly up to full speed then slows down again as it nears 1.

I currently have a function using sine, in the form...

$$y = (\sin(πx/2))^2$$

This works ok, and gives me results in the range I require however it is too quick to reach the terminal velocity, I am looking for something which has a more gradual start / end and a steeper center (if that makes sense).

Any help would be appreciated!

  • 0
    You mean $y=(\sin(\pi x/2))^2$?2012-03-18
  • 0
    Yes, this is from code hence the difference :) Have updated the question, thanks.2012-03-18
  • 0
    You get the right formatting for $\sin$ using `\sin`. If you just type `sin`, $\TeX$ interprets that as juxtaposed variable names and italicizes them. Also, you get equations in display style by using double dollar signs instead of single dollar signs.2012-03-18

2 Answers 2

19

Something to try would be the parametrized function $$ f_\alpha(x)=\frac{x^\alpha}{x^\alpha+(1-x)^\alpha} $$ $f_1(x)=x$ and $f_2(x)$ looks like this

$\hspace{5cm}$curve

As $\alpha$ gets bigger, the slope in the middle becomes greater and the ends at $x=0$ and $x=1$ become flatter. As $\alpha\to\infty$, the curve tends toward a step function.

  • 0
    This is pure simplicity, thanks.2012-03-18
  • 0
    Lovely! Thanks @robjohn!2014-02-27
  • 0
    So much more intuitive than the "famous" Penner solutions! And can be coded much more succinctly, too! Thank you!2015-04-08
  • 0
    Is there a way to make similar function for "ease-in" effect, withiut "out"?2015-08-09
  • 0
    @raacer: how would you like the function to look? I am not sure what you mean by "ease-in without ease-out".2015-08-10
  • 0
    @robjohn: I mean it should be exactly the same from 0 to 0.5, and then it should be continued as a straight line in the top right direction from 0.5 to the infinity.2015-08-10
  • 0
    You can create a piecewise function that will do almost anything. However, this function was supposed to be from $[0,1]$ to $[0,1]$, so I am not certain where $\infty$ comes in.2015-08-11
  • 0
    Note for use in software: Using this for ease in/out of a camera animation, I found even α = 2 to be too much easing. Rather than compute a fractional power such as 1.5, I did linear interpolation between `x` and `f2(x)`: `(1-w) * x + w * f2(x)`, where `w` is in `(0..1)` to give a range of functions with increasing amount of ease-in/out.2018-04-20
  • 0
    @ToolmakerSteve: linear interpolation is good since it maintains the property $f(x)+f(1-x)=1$ that $f_\alpha$ has. Using $\alpha=1$ and $\alpha=2$ definitely simplify the computation.2018-04-20
7

You could also use a polynomial that's $0$ at $0$, $1$ and $1$ and has zero derivative at both ends; the unique polynomial of degree $3$ with those properties is $y=x^2(3-2x)$.

In both of those functions, you can replace $x$ by

$$u=\frac12+\frac{\arctan\left(\alpha\left(x-\frac12\right)\right)}{2\arctan\frac\alpha2}$$

and choose $\alpha$ to achieve the desired steepness, with $\alpha\to0$ corresponding to $u=x$ and $\alpha\to\infty$ corresponding to a step function.

  • 0
    Perfect, many thanks for your help (with question formatting and answer!)2012-03-18
  • 0
    @Simon: You're welcome.2012-03-18
  • 1
    @Simon: if you think the answer is useful (and since you've accepted it, it seems you do), you might also want to upvote it (you can only accept one answer, but you can upvote as many as you like).2012-03-18