Add math::quadratic_spline_acceleration helper
All checks were successful
Run tests / Run tests (push) Successful in 7m16s

This commit is contained in:
Nikita Lisitsa 2026-08-16 17:03:17 +03:00
parent 156a58a59a
commit 7e9596d77f

View file

@ -235,4 +235,17 @@ namespace psemek::math
return T{1} / T{2} - std::sin(std::asin(T{1} - T{2} * x) / T{3});
}
// Stateless piecewise-quadratic spline acceleration
// based on current velocity, current distance to target,
// and max acceleration
template <typename T>
T quadratic_spline_acceleration(T velocity, T distance, T max_acceleration)
{
T max_velocity = std::sqrt(2.f * std::abs(distance) * max_acceleration);
return max_acceleration
* (distance < 0.f ? -1.f : 1.f)
* ((std::abs(velocity) < max_velocity || (distance > 0.f) != (velocity > 0.f))? 1.f : -1.f)
;
}
}