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.
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?
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>