# Time and distance where velocity is a function of time

I'm creating a video game set in space in which spaceships travelling between places accelerate until they hit a maximum velocity. They then travel at that velocity until a time when they need to start decelerating so as to arrive at their destination and not overshoot. There is no relativity or friction or anything else 'fancy' involved

For the algorithm I'm writing to do this, I need to know

a) the time it will take a ship to reach the half way point in its journey (assuming it continues to accelerate forever), and

b) the time it will take to reach maximum velocity, and

c) the distance travelled at time t (assuming continuous acceleration).

I can then use that to tell the ship at what time to start decelerating, depending on how far the whole journey is.

However, to accelerate the ships, I multiply their current velocity by 1.5 every second (to decelerate, I divide by 1.5). i.e. v(t) = v(t-1) * 1.5

I can also assume Initial velocity (velocity at time 0) is a constant and always positive

If anyone can point me in the right direction as to what formula to use (or even better, the pseudo-code to do it), I'd be most appreciative

I multiply their current velocity by 1.5 every second

OK, sounds like a discrete time problem. For continuous acceleration:

$v[n] = v[0] \cdot (1.5)^n$

So, the answer to (c) is:

$x[n] = \sum \limits_{i=1}^{n}v[i-1] = \frac{2}{3} \cdot v[0] \cdot \sum \limits_{i=1}^{n}(1.5)^i = 2 \cdot v[0] \cdot [(1.5)^n - 1]$

For (b), if the maximum velocity is V > v[0], then the time required to reach V is:

$n =\dfrac{ln (\frac{V}{v[0]})}{ln(1.5)}$

For (a), if $x[N]$ is the distance traveled under continuous acceleration, then you're looking for the $n$ where $x[n] = x[N] / 2$

For N large enough, the solution is:

$n = \dfrac{ln(\frac{(1.5)^N}{2})}{ln(1.5)}$

Update: for emphasis and to simplify your code, for large n:

$x[n] \approx 2 \cdot v[n]$

• I didn't understand quite what N was in your solution for part a), so I used Erik's instead, but otherwise, worked perfectly! :D Commented Jun 26, 2012 at 9:59
• Thanks for the feedback and I'm glad you stitched together the answers to get your solution! Commented Jun 27, 2012 at 1:11

I've watched your profile and I guess you're not a real physics guy. And I've read the following sentence.

However, to accelerate the ships, I multiply their current velocity by 1.5 every second (to decelerate, I divide by 1.5). i.e. v(t) = v(t-1) * 1.5

This multiplication will make the equations you need a little bit more difficult. You'll need exponential functions, logarithms. Basic programming languages are quite bad at performing this operations.

If you want to keep the multiplication.

The solution of $v(t) = v(t-1) * 1.5$ will be $v(t) = v_0(1,5)^t$ Where the initial velocity is $v_0=v(0)$

c) x(t)=$\int{v}{dt} = \frac{v_0.1.5^t}{ln(1.5)}$ Edited a stupid mistake: thanks to Alfred Centauri

a)The moment you reach your goal:

$x(t)=x_{goal}\implies t=log_{1.5}(\frac{x_{goal}ln(1.5)}{v_0})$ Where $log_{1.5}$ is the logarithm in base 1.5

b) The moment you'll reach that maximum velocity

$v(t)=v_{max} \implies t=log_{1.5}(\frac{x_{goal}}{v_0})$

A model which a physicist would like better.

When you'll try to run the previous model it will look quite silly. You'll notice that it will look quite silly. At the start your space ship will gain speed incredibly slow. But when you've allways reach $v_max$ it will accelerate way to fast.

A better model:

• Assume the acceleration is a constant $a(t)=c$
• This implies $v(t)=c.t+v_0$
• Which implies $x(t)=c.\frac{t^2}{2}+v_0.t+x_0$

Which is a lot easier to work with and will look more realistic.

• x(t) = dv/dt? Doh! Don't you hate it when that happens! :) Commented Jun 23, 2012 at 21:24
• Actually, from an aesthetics point of view, it works quite well. The initial slower acceleration lasts for about half a second before the ship zips off. The other consideration is that the ship's max velocities range from between x2 and x10 speed of light, whilst the radius of the player camera is about 10,000m. Low constant acceleration means it takes too long for ships to get to max velocity for the game to be fun. Too high a constant acceleration and the ship seems to simply disappear when it starts accelerating. Commented Jun 26, 2012 at 10:12