Solving time needed to travel a given distance, given simulated (not real physics) properties of acceleration of object

931 Views Asked by At

For a small personal project I'm looking at travel time of objects in a video game called EVE-Online.

I need to calculate time it will take object to travel from stand-still, constantly accelerating, until it reaches $x$ meters.

In this game objects velocity while accelerating in straight line is defined with equation:

$$v(t)= s(1-e^{-\frac{t}{a}})$$

Where $a$ and $s$ are object specific and unchanging for duration of acceleration.

The function is constructed in a way that $v(t)$ will approach $s$ (maximum speed of object), but never reaching it.

What I did to solve I would call a brute force approach: I calculated $v(t)$ for each second of simulation and summed it up until reaching $x$ (not exactly, as You will overshoot but my system will work fine with precision around one second).

Because I have to calculate this value for many thousand of objects it is impractical to perform this simulation for each and every single one due to computing time needed (I want my system to be relatively fast) and I'm looking for directly solving for $t$ needed to sum of $v(t)$ equaling to $x$.

Is there a way to solve this other than just sum up $v(t)$ at each second or fraction of a second until reaching designated goal?

2

There are 2 best solutions below

5
On BEST ANSWER

You can work out a formula for distance travelled using an integral :

$$x(t) = \int_0^t{v(t) dt}$$

When you work out that equation you can solve it for $t$ in terms of $x$.

What you get is :

$$x(t) = s t + sa ( e^{-t/a} - e^0 )$$

Which is :

$$x(t) = st - sa( 1 - e^{-t/a} )$$

Now we cannot provide a convenient formula for $t(x)$, the time to travel a given distance. A basic numerical approach would be to use Newton's Method. Note that for that method you will need the derivative of $x(t)$ and this is simply the velocity $v(t)$

In your case you keep calculating new values of $t_n$ using :

$$t_{n+1} = t_n - \frac{x(t_n)-X_0}{v(t_n)}$$

Where $X_0$ is your target distance.

When $(t_n-t_{n-1})$ is small enough for your needs ( which should should not take many calculations ) you have your approximate answer. You can start with any value, but try $t_0 = 0$ for simplicity.

( Thanks to Claude Leibovici for spotting a silly sign error in my original post. ).

3
On

This is not an answer but it is too long for a comment.

As StephenG answered (I fixed a minor sign error in the solution), the equation $$X_0 = s\,t - s\,a\,\big( 1 - e^{-\frac t a} \big)$$ would require some numerical method (Newton being probably the simplest).

However, this equation has an explicit solution in terms of Lambert function $$t=\frac{X_0}{s}+a \,\Big(W\left(z\right)+1\Big)\qquad z=\exp\Big(-\big(1+\frac{X_0}{a \,s}\big)\Big)$$ The Wikipedia page gives approximation formulas for small values of the argument $z$ (you should use it).

In fact, for your curiosity, any equation which can write $A+Bx+C\log(D+Ex)=0$ shows explicit solution(s) in terms of Lambert function.