Racing Time Difference Formula

rocket452

New member
Joined
Jun 8, 2013
Messages
1
I am trying to develop an android app for a friend that uses the gps to tell you how many seconds ahead or behind you are from your target speed vs your actual speed.

For example I could drive for 1 min at 10mph, with '60mph' selected on the app. The app would then show me '-300sec' because I would be 5min behind if I had been going 60mph for 1min instead.

The formula I have is:

((actualSpeed - targetSpeed) / actualSpeed) * Time

so for the example:
((10mph - 60mph)/10mph) * 60sec = -300sec

I thought my formula was fine until i tried a different example:

I could drive for 1 min at 60mph, with '30mph' selected on the app. The app should then show me '+60sec' because I would be 1min ahead if I had been going 30mph for 1min instead.

so for the example:
((60mph - 30mph)/60mph) * 60sec = +30sec

With this example I'm getting +30sec instead of +60sec

I'm thinking that this formula has been used a lot with racing to optimize time but I can't seem to get a formula that works for all inputs.

Thanks in advance.
 
I don't think the idea you have is going to transfer well to real-life (every time they stop, the app would say -infinity seconds). Unless you mean to calculate the average speed the user has been going from t=0 to t=present.

Here is how I would go about doing it: The user specifies a speed they wish to maintain: \(\displaystyle V\). Grab speed values at small, say 1s intervals. If the app has been running for \(\displaystyle T\) seconds you will have \(\displaystyle T\) velocities: \(\displaystyle v_1,...,v_T\). The average speed the user has gone is:

\(\displaystyle v_{\text{ave}}(T)=\displaystyle \dfrac{1}{T}\sum_{t=1}^{T}v_t\).

The distance covered will be: \(\displaystyle D_T=T\cdot v_{\text{ave}}(T)\). The distance covered, should they have been traveling at the specified speed is \(\displaystyle d_T=T\cdot V\).

Now calculate how much longer it will take them to make up for the distance if they maintain their current average speed: \(\displaystyle t_T = \dfrac{d_T-D_T}{v_{ave}(T)}\). This will have the opposite signs of what your app does, so you can do the subtraction in the opposite manner if you want.

Or if you now wish to use their current speed (still some issues of when their are slow-downs): \(\displaystyle t_T = \dfrac{d_T-D_T}{v_T}\)

edit: A way to optimize the app (instead of summing these things up every time) is to do it recursively.

\(\displaystyle v_{\text{ave}}(T) = \dfrac{(T-1)\cdot v_{\text{ave}}(T-1) + v_T}{T}\)
 
Last edited:
Top