Time taken to traverse distance, respecting acceleration and decceleration I am working on project simulating vehicle transport.
My current function that calculates time required to get from A to B is simple 

$time = dist/speed$

I need to change this function, so that it will account for acceleration and decceleration. I found some solutions, that work if the car is allowed to get to full speed, but I also need to account for the cases in which the distance is too short to attain maximum speed. I know ,this question is little bit below math.stackexchange difficulty, and I'm sorry for that, but I do not have slightest idea where to start.  If you can point me in the general direction of the solution, I would be extremely grateful.
A vehicle must travel a distance $D$ and we wish to find the time it takes $T$ with the following assumptions:

a) The vehicle starts at rest and must end at rest

b) It accelerates at a constant rate $a$ and decelerates at a constant rate $d$ ($d$ is negative)

c) When (or if) it achieves its maximum speed $V_{max}$ it cruises at this speed until it must decelerate

Two formulas used in the following: $$V_{final}=V_{initial}+at$$

$$s=V_{initial} \, t+ \frac{1}{2}at^2$$

where $V$ is speed, $t$ is time and $s$ is distance.

Let's call $V_1$ the vehicle's speed after accelerating for a time $t_1$. As it starts at rest, we have $$V_1 = at_1$$

Let's call $V_2$ the vehicle's speed after decelerating for a time $t_2$. As it ends at rest, we have $V_2 = 0$, which means $$0= V_1 + dt_2$$

Combining these two equations we get $$t_2= -\frac a d t_1$$

Now let's look at the distances covered. For the acceleration phase we find $$s_1=\frac{1}{2}at_1^2$$

and for the deceleration phase we find $$s_2=V_1t_2+ \frac{1}{2}dt_2^2$$

Inserting the equation for $t_2$ found above, we can convert the last equation to $$s_2=-\frac{1}{2}\frac{a^2}{d}t_1^2$$

Let's assume for the moment that the vehicle never reaches $V_{max}$. This means there is only an acceleration phase and a deceleration phase. Which means $D = s_1 + s_2$. Which means $$D = \frac{1}{2}at_1^2(1- \frac a d)$$

Extracting $t_1$ from this equation we find $$t_1 = \sqrt{\frac{2D}{a(1-\frac a d)}}$$

We are now ready to give the final answers. Using $t_1$ above, calculate the speed achieved during the acceleration phase ($V_1=at_1$) and compare it with $V_{max}$. 

1. $V_1 \lt V_{max}$

We are done. The vehicle never reaches its maximum speed and $$T = t_1+ t_2$$

2. $V_1 \ge V_{max}$

The vehicle does reach its maximum speed. The time it takes to reach this speed will be $$t_{max}=\frac{V_{max}}{a}$$

This means the distance it covers during the acceleration and deceleration phases will be $$s = \frac{1}{2}at_{max}^2(1- \frac a d)$$

The time it spends cruising at $V_{max}$ must then be $$t_{cruise}=\frac{D-s}{V_{max}}$$

Giving the total time as $$T = t_{max}(1- \frac a d)+ t_{cruise}$$
If uniform acceleration (or deceleration) , start (or end) speed are known then we have time $t$

$$ t = (v-u)/a = (\sqrt {2 a s + u^2}-u)/a $$

where $u,v$ are speeds at start and end. If $a&gt;=&lt;0$ or positive acceleration, then  $ v&gt;=&lt;u. $