Add math::quadratic_spline_acceleration helper
All checks were successful
Run tests / Run tests (push) Successful in 7m16s
All checks were successful
Run tests / Run tests (push) Successful in 7m16s
This commit is contained in:
parent
156a58a59a
commit
7e9596d77f
1 changed files with 13 additions and 0 deletions
|
|
@ -235,4 +235,17 @@ namespace psemek::math
|
||||||
return T{1} / T{2} - std::sin(std::asin(T{1} - T{2} * x) / T{3});
|
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)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue