Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I'm running a simulation that updates in a fixed time $dt$.
I have a car moving straight with initial velocity $v_0$. This car has to move exactly a distance $D$ in $t$ seconds (for simplicity, suppose $t = f \times dt$, where $f$ is an integer).
How can I find the deceleration for the car to stop exactly after traversing $D$?
I'm getting confused because if I know the car will stop after $f$ frames, then the deceleration should be $(v_0 \div f)$, but when I do
If I understand you correctly, you're saying that your car is moving at an initial speed $v_0$, and you want it to travel a given distance $D$and stop in a given time $t$. The problem is that if the acceleration is uniform, you have (from the uniform-acceleration kinematic equations
$$
D = v_0 t + \frac{1}{2} a t^2
$$
where $a$ is the acceleration. But you also have $a = - v_0/t$, meaning that
$$
D = v_0 t - \frac12 v_0 t = \frac12 v_0 t.
$$
In other words, requiring both that the car come to a stop after a time $t$ and that the acceleration is constant uniquely determines the distance it will travel. If it happens that you don't have $D = \frac12 v_0 t$, then your car will not stop in the "right place".
A possible way around this would be to relax the assumption of uniform acceleration. It should be possible to get the car to stop in any distance between $0$ and $v_0 t$ by dividing the interval $t$ into two parts and allowing the car to have different accelerations during these two intervals. (You can see this by sketching possible graphs of the car's velocity as a function of time, and using the fact that the distance the car travels is equal to the area under the velocity graph.)