# Racing Time Difference Formula

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.

-

As you are travelling the same distance, $d_1=d_2=d$, where $\cdot_1$ indicates the target results and $\cdot_2$ indicates the actual results.

We know $d=s_1t_1=s_2t_2$, where $t_*$ is the time and $s_*$ is the speed. You are interested in $t_2-t_1$. The above equation can be solved for $t_1$ as $t_1=\dfrac{s_2}{s_1}t_2$. The difference in time is then $$t_2-\dfrac{s_2}{s_1}t_2=\left(1-\dfrac{s_2}{s_1}\right)t_2.$$ This is the forumula for the diffence in time where $s_1$ is your target speed, $s_2$ is your actual speed and $t_2$ is the actual time it took.

-
This gives you how slow you are. The OP wants you it to be negative when you are behind so you must negatate (that is now a word) that. –  PyRulez Jun 8 '13 at 22:53
@PyRulez You are correct; I understood the question to mean the opposite time. –  Daryl Jun 9 '13 at 1:01
Right I would like to have a positive output when you are ahead, and a negative output when you are behind. I don't think that's possible with 1 formula. –  Brady Jun 9 '13 at 23:32
@Brady The current formulation has been edited to have the correct sign. The result is the same as the answer by Angela. –  Daryl Jun 9 '13 at 23:40
@Daryl so using this formula if your going at 10mph and your target speed is 20mph. (1 - 10/20) = .5 each second. You are going under your target speed but this value is still positive. –  Brady Jun 17 '13 at 22:15

Try $\displaystyle \left( 1-\frac{\text{target speed}}{\text{actual speed}} \right) \times \text{time}$

-
So to use this with my first example, (1 - (10/60)) x 60 = 50sec. Is this accurate? I need the value to be negative when you are going slower than the selected speed. –  Brady Jun 9 '13 at 0:52
Do not forget to explain your answer. –  PyRulez Jun 9 '13 at 16:44
This formula is just what I need for when you are going faster than the target Speed. Thanks. I guess I will have to use a 2nd formula for when the target speed > actual –  Brady Jun 9 '13 at 23:34