# How to determine when to decelerate to reach a destination at 0 velocity?

(Sorry, not sure whether this belongs here on the Physics StackExchange or the Math StackExchange.)

I'm creating a computer game in which there is a computer-controlled car that needs to travel along a straight line (thus making this problem effectively 1-dimensional) and reach a destination coming to a rest at 0 velocity. This car "thinks" every second and decides whether (and by how much) to accelerate or decelerate.

Here are the variables the car knows about:

• Dist = Our current distance to the destination in meters
• Vel = Our current velocity towards the destination in meters/second
• MaxAccel = The maximum amount by which we can increase our velocity every second.
• MaxDecel = The maximum amount by which we can decrease our velocity every second.
• Accel = The change in velocity per second. The car can change its acceleration every second to any number in the range [-MaxDecel, MaxAccel].
• Drag = The amount by which the car's velocity is reduced every second, as a fraction of its current velocity that second.

So to be as clear as I can, here's the math that runs every second to update the car simulation:

Accel = some amount between [-MaxDecel, MaxAccel] as chosen by the computer

New_Vel = (Vel + Accel) * (1 - Drag)

New_Dist = Dist - New_Vel

So my question is: Every time the car "thinks", what formula(s) should it use to determine the ideal value of Accel in order to reach its destination (with a 0 final velocity) in as little time as possible? (Approximate solutions are acceptable.)

(In the event that the car's initial velocity is too high and it can't decelerate fast enough to achieve 0 velocity by the time it reaches its destination, then it should come to a rest as close as possible to the destination.)

Please let me know if you have any questions.

• No one would ever realistically use a variable you call 'Drag' when you're already using 'Accel'. New_Vel = (Vel + Accel) * (1 - Drag) makes no sense at all. See the answer below.
– Gert
Nov 12, 2015 at 17:50
• What I'm trying to get at with separating the Drag variable is that the deceleration due to drag changes every second depending on what the velocity is that second (i.e., drag isn't constant). My problem is that I don't know how I need to modify the "classical equations of motion" to take that into account. Nov 12, 2015 at 18:05
• The only way to take drag into account is using complicated equations of motion. Drag manifests itself as a force: $F_D \propto v^2$. Your equation of motion then becomes $ma=-F_D-F_B$ where $F_B$ is an additional braking force and $a=dv/dt$. Good luck solving that for your purposes!
– Gert
Nov 12, 2015 at 18:30

## DISCLAIMER

Your "simulation" is rather crude and not very realistic (you know that already). So you either accept real physics solutions, or this question needs to close as it pertains to non-mainstream physics.

## Constant Acceleration (No Drag)

A body under constant acceleration $a$ between speeds $v_i$ and $v_f$ will need the following distance

$$x = \frac{v_f^2-v_i^2}{2 a}$$

In your case the acceleration is negative $a<0$ and $v_f=0$, yielding $x =\frac{ v_i^2}{2 |a|}$.

## Variable Acceleration (With Drag)

The general formula for the distance traveled between two speeds with variable acceleration is $$x = \int_{v_i}^{v_f} \frac{v}{a}\,{\rm d}v$$

The above assumes that acceleration is only a function of speed. For example:

1. Constant thrust with quadratic drag $$\color{blue}{ a = a_T - \beta v^2 }$$ $$x = \int_{v_i}^{v_f} \frac{v}{a_T -\beta v^2}\,{\rm d}v = \frac{1}{2\beta} \ln \left( \frac{a_T-\beta v_i^2}{a_T-\beta v_f^2} \right)$$
2. Constant Power with constant drag $$\color{blue}{a = \frac{p}{v} - b_F}$$ $$x = \frac{v_i^2-v_f^2}{2 b_F} + \frac{p(v_i-v_f)}{b_F^2}+\frac{p^2}{b_F^3} \ln \left( \frac{b_F v_i -p}{b_F v_f-p} \right)$$
3. Constant Power with quadratic drag $$\color{blue}{ a = \frac{p}{v} - \beta v^2 }$$ $$x = \int_{v_i}^{v_f} \frac{v}{\frac{p}{v} -\beta v^2}\,{\rm d}v = \frac{1}{3 \beta} \ln \left( \frac{p-\beta v_i^3}{p-\beta v_f^3} \right)$$

The above applies to both acceleration $a>0$ and deceleration $a<0$ if the initial and final speeds are set appropriately.

• Similarly to find the time it takes to go between two speeds is $$t = \int \frac{1}{a}\,{\rm d}{v}$$ Oct 12, 2017 at 18:44

The classical equations of motion should do it for you. This one for example:

$$v_{final}=v_{initial}+at$$

Plug in your maximum deceleration (the most negative $a$ possible) and you other values. You can easily find the time $t$ is will take to reach 0 m/s.

If the value for the maximum deceleration is not constant, then those equations don't apply. Instead you must use the basic definition and start from scratch to find your own fitting motion equation with:

$$v=da/dt$$

• Yeah, I understand the classical equations of motion, but none of them take my version of "drag" into account, and I'm not sure how to modify those equations to do that. Nov 12, 2015 at 18:05
• @WaltD: They don't take your 'version' of drag into account because that's not how it works.
– Gert
Nov 12, 2015 at 18:43
• Yeah sounds like this is really a problem for Math StackExchange, not physics. Thanks anyway! Nov 12, 2015 at 18:44
• @waltd The equations of motions are true under the condition that you have constant acceleration. Since you are saying that there is a specific maximum deceleration which I assumed was a specific constant value, then this is just the acceleration you should put into the equation. How to reach this acceleration through all the forces acting in the object is then another problem, which is to be solved with Newton's laws. If there is a non-constant drag force, then the engine must apply a gradually larger forward force to maintain the acceleration we want for the motion equation. Nov 12, 2015 at 19:50
• If on the other hand the acceleration is not constant, you must start with the basic definitions to find your motion equation for your exact situation. See my update to the answer Nov 12, 2015 at 19:55

First there is no need to use intermediate values of acceleration, logic behind is that you want to accelerate as strongly as possible and then stop as rapidly as possible.

The solution to the problem is easy:

1) define how many meters you will need to stop with MaxDecel from your initial velocity.

2) Take the remaining distance X, and plug it into the following system of equations.

    1. MaxAccel*t1=MaxDecel*t2


(The velocity difference during acceleration and deceleration is the same)

    2. Vini*t1+(Vini+MaxAccel*t1)*t2+0.5*MaxAccel*t1^2-0.5*MaxDecel*t2^2=X


Find t1 and t2 and use MaxAccel for t1 and MaxDecel for t2

Even though Physics is probably not the best forum for this question I like it because it is very realistic. It also reminds me a bit the Fermat's principle which says that light will travel the path which takes the shortest time.