constantAccelerationEaseInOutWithInitialVelocity function
double
constantAccelerationEaseInOutWithInitialVelocity(
- double t,
- double initialVelocity
)
Implementation
double constantAccelerationEaseInOutWithInitialVelocity(
double t, double initialVelocity) {
if (t >= 1) {
return 1;
}
double sqrtPart = sqrt(2 * sq(initialVelocity) - 4 * initialVelocity + 4);
double m =
(2 - initialVelocity + (initialVelocity < 2 ? sqrtPart : -sqrtPart)) / 2;
double ax = -initialVelocity / (2 * m);
double ay = initialVelocity * ax / 2;
double h = (ax + 1) / 2;
if (t < h) {
return m * sq(t - ax) + ay;
} else {
return -m * sq(t - 1) + 1;
}
}