toss function

TossResult toss(
  1. double x,
  2. double y,
  3. double vx,
  4. double vy,
  5. double age,
  6. double g, [
  7. double floor = 0.0,
])

Implementation

TossResult toss(
  double x,
  double y,
  double vx,
  double vy,
  double age,
  double g, [
  double floor = 0.0,
]) {
  final tl = g > 0.0
      ? (-vy + math.sqrt(math.max(0.0, vy * vy + 2.0 * g * (floor - y)))) / g
      : double.infinity;
  if (age < tl) {
    return TossResult(
      x: x + vx * age,
      y: y + vy * age + 0.5 * g * age * age,
      vx: vx,
      vy: vy + g * age,
      landed: false,
      at: tl,
      lx: x + vx * tl,
    );
  }
  return TossResult(
    x: x + vx * tl,
    y: floor,
    vx: 0.0,
    vy: 0.0,
    landed: true,
    at: tl,
    lx: x + vx * tl,
  );
}