Documentation
    Preparing search index...

    Class SpringDamper

    A spring-damper controller stepped by the exact exponential solution.

    const smoother = new SpringDamper({ frequencyHz: 4, dampingRatio: 1 });
    const state = { value: 0, velocity: 0 };

    // Once per frame or fixed step, with the injected delta:
    smoother.update(state.value, target, state.velocity, deltaSeconds, state);

    Construction is the only validated moment: the parameters are immutable, so a retuned spring is a new instance (a mid-flight stiffness change would invalidate the cached step and, more importantly, is a different physical system — the caller should decide what happens to the velocity).

    Index
    angularFrequency: number

    Undamped natural frequency ωₙ in radians per second.

    damping: number

    Viscous damping per unit mass, 2ζωₙ, in s⁻¹.

    dampingRatio: number

    Damping ratio ζ: < 1 oscillates, 1 critical, > 1 overdamped.

    frequencyHz: number

    Undamped natural frequency in hertz.

    stiffness: number

    Spring constant per unit mass, ωₙ², in s⁻².

    • Advances one scalar spring by deltaSeconds towards target.

      Parameters

      • current: number

        Current value.

      • target: number

        Value the spring pulls towards; held constant over the step.

      • velocity: number

        Current rate of change, per second.

      • deltaSeconds: number

        Step in seconds (§7a); finite and > 0.

      • Optionalout: SpringDamperResult

        Record written and returned; allocated when omitted.

      Returns SpringDamperResult

      RangeError if deltaSeconds is not a finite positive number.