FigmaSpringCurve constructor

FigmaSpringCurve(
  1. double stiffness,
  2. double damping,
  3. double mass, [
  4. double initialVelocity = 0.5,
])

Creates a FigmaSpringCurve curve

Implementation

FigmaSpringCurve(
  double stiffness,
  double damping,
  double mass, [
  double initialVelocity = 0.5,
]) {
  _mW0 = math.sqrt(stiffness / mass);
  _mZeta = damping / (2 * math.sqrt(stiffness * mass));

  if (_mZeta < 1) {
    // Under-damped.
    _mWd = _mW0 * math.sqrt(1 - _mZeta * _mZeta);
    _mA = 1;
    _mB = (_mZeta * _mW0 + -initialVelocity) / _mWd;
  } else {
    // Critically damped (ignoring over-damped case for now).
    _mA = 1;
    _mB = -initialVelocity + _mW0;
  }
}