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