timeAtX method

double timeAtX(
  1. double x
)

The time at which the value of x(time) will equal x.

Returns double.infinity if the simulation will never reach x.

Implementation

double timeAtX(double x) {
  if (x == _x) {
    return 0.0;
  }
  if (_v == 0.0 || (_v > 0 ? (x < _x || x > finalX) : (x > _x || x < finalX))) {
    return double.infinity;
  }
  return _newtonsMethod(
    target: x,
    initialGuess: 0,
    f: this.x,
    df: dx,
    iterations: 10
  );
}