pub struct Spring { /* private fields */ }Expand description
The analytic response of a SpringDesc released from an initial
displacement + velocity toward equilibrium at 0.
Positions returned by Spring::position are displacements from
equilibrium (the target), so equilibrium is always 0. The closed-form
solution branches on the damping regime; all three are exact (no numerical
integration), which is what lets a fling be evaluated at an arbitrary frame
time without accumulating step error.
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn new(desc: SpringDesc, x0: f64, v0: f64) -> Self
pub fn new(desc: SpringDesc, x0: f64, v0: f64) -> Self
Solve the spring released from displacement x0 (relative to
equilibrium) with initial velocity v0.
Degenerate parameters (non-positive mass/stiffness) fall back to a
critically-damped unit spring so the constructor never produces NaN.
Sourcepub fn position(&self, t: f64) -> f64
pub fn position(&self, t: f64) -> f64
The displacement from equilibrium at elapsed time t (seconds).
Sourcepub fn velocity(&self, t: f64) -> f64
pub fn velocity(&self, t: f64) -> f64
The velocity (d displacement / d t) at elapsed time t (seconds).
Sourcepub fn is_at_rest(&self, t: f64, epsilon: f64) -> bool
pub fn is_at_rest(&self, t: f64, epsilon: f64) -> bool
Whether the spring has effectively settled at equilibrium by time t:
both |position| and |velocity| are below epsilon.