Skip to main content
Clarifying that initial alpha is linear in space. The second step gets us a value that's linear in time.
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

So long as y1 and y2 are distinct, you can recover alpha with an inverse lerp:

$$\begin{align} y &= (1 - \alpha) y_1 + \alpha * y_2\\ y &= y_1 + \alpha (y_2 - y_1)\\ y - y_1 &= \alpha (y_2 - y_1)\\ \frac {y - y_1 } {y_2 - y_1} = \alpha \end{align}$$

This gives us a linear measure of progress from y1 (0% = 0) to y2 (100% = 1). Note that this does not yet factor in the non-linear relationship between time and position, this is just measuring what ratio of the distance we've covered in space.

We can then apply any easing function we want to it. Let's say we use this easing formula:

$$\alpha = 1 - (1 - \frac t {\text{duration}})^n$$

We can take its inverse to recover the time value at which we would reach this value for alpha:

$$\begin{align} \alpha &= 1 - (1 - \frac t {\text{duration}})^n\\ 1 - \alpha &= (1 - \frac t {\text{duration}})^n\\ (1 - \alpha)^{\frac 1 n} &= 1 - \frac t {\text{duration}}\\ 1 - (1 - \alpha)^{\frac 1 n} &= \frac t {\text{duration}}\\ \text{duration} \cdot \left(1 - (1 - \alpha)^{\frac 1 n}\right) &= t \end{align}$$

Now you can add your time delta to t (clamp it so it does not exceed the total ease duration), and run this back through your easing formula to get the alpha value for the next position along the curve.

So long as y1 and y2 are distinct, you can recover alpha with an inverse lerp:

$$\begin{align} y &= (1 - \alpha) y_1 + \alpha * y_2\\ y &= y_1 + \alpha (y_2 - y_1)\\ y - y_1 &= \alpha (y_2 - y_1)\\ \frac {y - y_1 } {y_2 - y_1} = \alpha \end{align}$$

This gives us a linear measure of progress from y1 (0% = 0) to y2 (100% = 1).

We can then apply any easing function we want to it. Let's say we use this easing formula:

$$\alpha = 1 - (1 - \frac t {\text{duration}})^n$$

We can take its inverse to recover the time value at which we would reach this value for alpha:

$$\begin{align} \alpha &= 1 - (1 - \frac t {\text{duration}})^n\\ 1 - \alpha &= (1 - \frac t {\text{duration}})^n\\ (1 - \alpha)^{\frac 1 n} &= 1 - \frac t {\text{duration}}\\ 1 - (1 - \alpha)^{\frac 1 n} &= \frac t {\text{duration}}\\ \text{duration} \cdot \left(1 - (1 - \alpha)^{\frac 1 n}\right) &= t \end{align}$$

Now you can add your time delta to t (clamp it so it does not exceed the total ease duration), and run this back through your easing formula to get the alpha value for the next position along the curve.

So long as y1 and y2 are distinct, you can recover alpha with an inverse lerp:

$$\begin{align} y &= (1 - \alpha) y_1 + \alpha * y_2\\ y &= y_1 + \alpha (y_2 - y_1)\\ y - y_1 &= \alpha (y_2 - y_1)\\ \frac {y - y_1 } {y_2 - y_1} = \alpha \end{align}$$

This gives us a linear measure of progress from y1 (0% = 0) to y2 (100% = 1). Note that this does not yet factor in the non-linear relationship between time and position, this is just measuring what ratio of the distance we've covered in space.

We can then apply any easing function we want to it. Let's say we use this easing formula:

$$\alpha = 1 - (1 - \frac t {\text{duration}})^n$$

We can take its inverse to recover the time value at which we would reach this value for alpha:

$$\begin{align} \alpha &= 1 - (1 - \frac t {\text{duration}})^n\\ 1 - \alpha &= (1 - \frac t {\text{duration}})^n\\ (1 - \alpha)^{\frac 1 n} &= 1 - \frac t {\text{duration}}\\ 1 - (1 - \alpha)^{\frac 1 n} &= \frac t {\text{duration}}\\ \text{duration} \cdot \left(1 - (1 - \alpha)^{\frac 1 n}\right) &= t \end{align}$$

Now you can add your time delta to t (clamp it so it does not exceed the total ease duration), and run this back through your easing formula to get the alpha value for the next position along the curve.

Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

So long as y1 and y2 are distinct, you can recover alpha with an inverse lerp:

$$\begin{align} y &= (1 - \alpha) y_1 + \alpha * y_2\\ y &= y_1 + \alpha (y_2 - y_1)\\ y - y_1 &= \alpha (y_2 - y_1)\\ \frac {y - y_1 } {y_2 - y_1} = \alpha \end{align}$$

This gives us a linear measure of progress from y1 (0% = 0) to y2 (100% = 1).

We can then apply any easing function we want to it. Let's say we use this easing formula:

$$\alpha = 1 - (1 - \frac t {\text{duration}})^n$$

We can take its inverse to recover the time value at which we would reach this value for alpha:

$$\begin{align} \alpha &= 1 - (1 - \frac t {\text{duration}})^n\\ 1 - \alpha &= (1 - \frac t {\text{duration}})^n\\ (1 - \alpha)^{\frac 1 n} &= 1 - \frac t {\text{duration}}\\ 1 - (1 - \alpha)^{\frac 1 n} &= \frac t {\text{duration}}\\ \text{duration} \cdot \left(1 - (1 - \alpha)^{\frac 1 n}\right) &= t \end{align}$$

Now you can add your time delta to t (clamp it so it does not exceed the total ease duration), and run this back through your easing formula to get the alpha value for the next position along the curve.