0
votes

I have an object that start at v0 (0m.s^-1) and needs to reach vf (10m.s^-1) in a distance of let say 25m.

Acceleration required?

This object updates its velocity using the following equation of motion:

    v(n) = v(n - 1) + a * dt

With dt being the time interval since last frame (last computation of the velocity). And n being the current frame index.

I know that in order to reach the final speed vf and going from v0 the formula for the acceleration is:

a = (vf * vf - v0 * v0) / (2 * d)

With d being the distance (25m in our example).

But I can not use this acceleration in my equation of motion, in fact I tried but I do not get the correct speed. So I guess it's because the acceleration is not fit to be used every time step.

So do you know the correct formula to retrieve the acceleration I can use inside my equation of motion?

1
Are your dts constant?BeyelerStudios
It should be, so let say yes 1/30 sec as an example.Silouane
Can we see the source code? I foresee a problem, if d/dt is integrated with constant velocity v(n), where as it should be v(n) + a*dt / 2.Aki Suihkonen
Source code is too big to show, but the formula for the position is: Vector3 pos = cur_pos + cur_vel * dt and for the velocity: Vector3 vel = cur_vel + acc * dtSilouane

1 Answers

1
votes

Your formula works for straight forward leap-frog:

var dt = 1.0 / 30;
var dp0 = 0, dp1 = 10;
var p0 = 0, p1 = 25;
var ddp = (dp1 * dp1 - dp0 * dp0) / (2 * (p1 - p0));
var list = document.getElementById("list");
for(var i = 0, p = p0, dp = dp0; p < p1; ++i) {
  // ddp = (dp1 * dp1 - dp * dp) / (2 * (p1 - p));
  p += dp * dt;
  dp += ddp * dt;
  var str = "";
  str += " p: " + Math.floor(p * 1000) / 1000;
  str += ", dp: " + Math.floor(dp * 1000) / 1000;
  str += ", ddp: " + Math.floor(ddp * 1000) / 1000;
  var text = document.createTextNode(str);
  var node = document.createElement("li");
  node.appendChild(text);
  list.appendChild(node);
}
<ol id="list"></ol>