0
$\begingroup$

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

for $i = 0, \dots , (f-1):$

$\quad$ position = position + speed * dt

$\quad$ speed = speed - deceleration * dt

The car doesn't stop where it should.

$\endgroup$
3
  • 1
    $\begingroup$ Check the units in "position = position + speed". $\endgroup$
    – Anyon
    Commented Nov 24, 2023 at 18:55
  • 1
    $\begingroup$ 1. it should be position = position + speed*dt, 2. how did you calculate the deceleration? $\endgroup$
    – trula
    Commented Nov 24, 2023 at 18:57
  • $\begingroup$ It is speed * dt, sorry, I mispelled. $\endgroup$
    – Daniel
    Commented Nov 24, 2023 at 19:15

2 Answers 2

0
$\begingroup$

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

$\endgroup$
0
$\begingroup$

Base your solution on the well-known

$s = u t + \frac{1}{2} f t^2 $

Solving for $f$

$\frac{1}{2} f t^2 = s - u t $

$f = \frac{2 (s - u t) }{t^2} $

You have used $D$ for $s$, and $v_0$ for $u$.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.