FrictionSimulation.through constructor

FrictionSimulation.through(
  1. double startPosition,
  2. double endPosition,
  3. double startVelocity,
  4. double endVelocity
)

Creates a new friction simulation with its fluid drag coefficient (cₓ) set so as to ensure that the simulation starts and ends at the specified positions and velocities.

The positions must use the same units as expected from x, and the velocities must use the same units as expected from dx.

The sign of the start and end velocities must be the same, the magnitude of the start velocity must be greater than the magnitude of the end velocity, and the velocities must be in the direction appropriate for the particle to start from the start position and reach the end position.

Implementation

factory FrictionSimulation.through(double startPosition, double endPosition, double startVelocity, double endVelocity) {
  assert(startVelocity == 0.0 || endVelocity == 0.0 || startVelocity.sign == endVelocity.sign);
  assert(startVelocity.abs() >= endVelocity.abs());
  assert((endPosition - startPosition).sign == startVelocity.sign);
  return FrictionSimulation(
    _dragFor(startPosition, endPosition, startVelocity, endVelocity),
    startPosition,
    startVelocity,
    tolerance: Tolerance(velocity: endVelocity.abs()),
  );
}