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?

  • $\begingroup$ Isolate the exponential term and use logarithms. $\endgroup$ – Claude Leibovici Dec 14 '15 at 11:06
  • $\begingroup$ If I understand it correctly that will only allow me to solve for time needed to reach specific V, which is easy. What I need is taking another step and calculating entire distance traveled in a specific amount of time. $\endgroup$ – Tetlanesh Dec 14 '15 at 11:08

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

  • $\begingroup$ Thank you @StephenG, I will take a good long look at Your response and try to implement what You are proposing when I'm back at home from work :) $\endgroup$ – Tetlanesh Dec 14 '15 at 12:09
  • $\begingroup$ Inspired by your answer, I proposed something which could be funny to test. Cheers. $\endgroup$ – Claude Leibovici Dec 14 '15 at 16:17
  • $\begingroup$ I'm yet to try Your solution @StephenG. Anyway I figured out how to approximate the result without iterations using the formula You provided . Since $v(t)$ approaches $s$, and I can (after reorganizing) use the original formula to solve for $t(v)$ (time needed to reach certain speed) to reach for example 99% of $s$, than use Your formula to calculate $x(t)$ to get distance traveled to this point, than substract $x(t)$ from $X_0$ to get distance remaining and from there just use $distance/s$ (with assumption that object moves at sped $s$). It will be approximation but close enough for my needs. $\endgroup$ – Tetlanesh Dec 16 '15 at 15:28
  • $\begingroup$ Thanks for the Integral function. I used it to estimate $t(x)$ like I wrote in my previous comment. My result are accurate enough for my needs. I will play with the Newtons Method and compare results anyway, but my approximation is many times faster computation wise and I can vectorize it. $\endgroup$ – Tetlanesh Dec 17 '15 at 23:29
  • $\begingroup$ For the first few examples I runned trough Newton's Method I got almost perfect result within 2/3 iterations, so its really efficient. Also as opposed to Your advice to start with t=0 I started with 1, as $v(0)=0$. Thank you very much @StephenG. $\endgroup$ – Tetlanesh Dec 17 '15 at 23:49

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.

  • $\begingroup$ Wikipedia has a note showing a numerical algorithm for $W(z)$ using Newton, which is sort of funny in the circumstances. $\endgroup$ – StephenG Dec 14 '15 at 17:55
  • $\begingroup$ @StephenG. It is a standard problem, just be sure. Lambert is, at least to me, one of the most important functions which already has a lot of practical applications. What has really good is that you worked the problem. The remaining is ... blabla $+\epsilon$ ! Cheers and thanks again. $\endgroup$ – Claude Leibovici Dec 14 '15 at 18:24
  • $\begingroup$ @StephenG. It seems that you have a small error (a sign) in the integration of the differential equation. I fixed my answer. $\endgroup$ – Claude Leibovici Dec 15 '15 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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