Calculating an object's stopping distance I'm trying to smooth the movement of a cursor which has a set acceleration and max speed. I wrote this function to calculate the stopping distance of an object given its speed and acceleration, and it works, but it seems a little ridiculous.

function getStoppingDist(speed, accel) {
  var dist = 0;
    while (speed &gt; 0) {
    dist += speed;
    speed -= accel;
  }
  return dist;
}


If the speed is 5 and acceleration is 1, its stopping distance is 5+4+3+2+1 = 15.

Surely there's a better way of doing this. What am I missing?
Considering this as a uniformly accelerated linear motion problem with given velocity and (negative) acceleration, you could use:

function getStoppingDist(speed, accel) {
  var dist = 0.5*Math.pow(speed,2)/accel;
  return dist;
}