FrictionSimulation constructor Null safety

FrictionSimulation(
  1. double drag,
  2. double position,
  3. double velocity,
  4. {Tolerance tolerance = Tolerance.defaultTolerance,
  5. double constantDeceleration = 0}
)

Creates a FrictionSimulation with the given arguments, namely: the fluid drag coefficient cₓ, a unitless value; the initial position x₀, in the same length units as used for x; and the initial velocity dx₀, in the same velocity units as used for dx.

Implementation

FrictionSimulation(
  double drag,
  double position,
  double velocity, {
  super.tolerance,
  double constantDeceleration = 0
}) : _drag = drag,
     _dragLog = math.log(drag),
     _x = position,
     _v = velocity,
     _constantDeceleration = constantDeceleration * velocity.sign {
    _finalTime = _newtonsMethod(
      initialGuess: 0,
      target: 0,
      f: dx,
      df: (double time) => (_v * math.pow(_drag, time) * _dragLog) - _constantDeceleration,
      iterations: 10
    );
  }