# Accelerating car catches up with another (accelerating) car

1. Aug 1, 2015

### TaurusI76

1. The problem statement, all variables and given/known data
I have the following situation: car 1 is distance di ahead of car 2. Car 1 has either a constant speed v1 or accelerates with a1 (I eventually want to cover both cases). Car 2 accelerates faster than car 1. Car 2 is eventually going to catch up with car 1. I want to calculate the distance that car 2 can accelerate until it has to slow down to reach car 1's speed.

The time/distance graph would look something like this:

2. Relevant equations
d1 = v1 * t + 0.5 * a1 * t2 - di
d2 = v2 * t + 0.5 * a2 * t2

3. The attempt at a solution
I could calculate the time that it takes for car 2 to catch up with car 1 by combining the two equations above, because when car 2 has caught up to car 1, it will have travelled the same distance as car 1 (plus the initial difference in distance di). So:
v1 * t + 0.5 * a1 * t2 - di = v2 * t + 0.5 * a2 * t2
When solving for t, I think I got the right time for the distances/speeds I put in my example calculation.

However, now I need to determine at what distance car 2 would have to start slowing down in order to not crash into car 1, but line up behind it. I know at what rate car 2 will decelerate, but I don't know from what initial speed vi it will decelerate from (since car 2 is accelerating, this depends on when it starts decelerating), so I can't calculate how far the car will travel when decelerating.

Is there a way to calculate this distance?

2. Aug 1, 2015

### Staff: Mentor

You cannot use the same t for both phases, in general they will have a different length.
You can set up two equations - you know the final distance difference and the final velocity difference, both are zero. That allows to find t1 and t2, the time spent in the phases respectively.

3. Aug 1, 2015

### TaurusI76

I'm not sure if I can follow your line of thought. What would t1 and t2 stand for then? I suppose t1 is the time that car 2 accelerates and t2 the time it decelerates - correct?
So what equations would I use to calculate them? If I use the same formula base as above (v * t + 0.5 * a * t2), how does knowing that final velocity difference and final distance difference are 0 help me eliminate the unknowns?

4. Aug 2, 2015

### Staff: Mentor

The acceleration and deceleration time, right.
The same as you posted. The velocity and position at the start of the deceleration phase will depend on the time of the acceleration phase.
It gives you two equations that have to be true. Those allow to find the t1 and t2, and those then allow to find everything else.

5. Aug 2, 2015

### TaurusI76

I still don't get how I can get rid of some of the unknowns. I updated the graph a little (for my better understanding)

What I managed to caluclate so far is the time/distance where the green line crosses the red line. But that is not of a lot of use to me, because the deceleration would have to take place before car 2 'crashes' into car 1. And the total distance/time until car 2 has reached car 1's speed is more/longer than that.

I tried the following (c1 is car 1, c2 is car 2, a is acceleration phase, d is deceleration phase, i is initial, f is final):
(I also added dgap, the gap to be kept to car 1, which is a two second gap of car 1's speed, so dgap = vc1f * 2)

dc1 = dgap + dc2a + dc2d
Putting in the formula for speed + acceleration and time gives me this:
vc1i * tc1 + 0.5 * ac1 * tc12 = (vc1f * 2) + (vc2ia * tc2a + 0.5 * ac2a * tc2a2) + (vc2di * tc2d + 0.5 * ac2d * tc2d2)

This leaves me with five unknown variables: tc1, vc1f, tc2a, vc2di, tc2d
I know that tc1 = tc2a + tc2d but what about the rest?

I also tried the t = (vf - vi) / a formula.
This results in:
(vc1f – vc1i) / ac1 = ((vfa - via) / aa) + ((vfd - vid) / ad)
This leaves me with four unknowns, and two of them are equal to either one of the others (vfa = vid and vc1f = vfd).
Still, two unknowns.
What am I doing wrong?

6. Aug 2, 2015

### Staff: Mentor

What is vc1f? The velocity of car 1 after the process? This can be expressed via the initial velocity, acceleration and the time.
What is vc2di? The initial velocity of car 2 in the deceleration phase? This is the same as the velocity after the acceleration phase, which you get based on the initial velocity, the acceleration in the acceleration phase and time.

Looks like two unknowns and two equations now, but the long formulas without explanation are messy.

7. Aug 2, 2015

### andrewkirk

Taurus, your problem is underdetermined. You have four unknowns, assuming that accel and decel are both constant and Car2 is always either accelerating or decelerating until the catch:

tc: the time of the catch-up
td: the time Car2 switches from accel to decel
a21: the rate of acceleration of Car2 in time 0 to td
a22: the rate of acceleration of Car2 in time td to tc

You have two equations, one to specify the difference in distances travelled at tc is (required) Gap, and one to specify that velocities are equal at tc.

So the problem is underdetermined. You need to specify two more things in order to solve it.
A simple way to get rid of one variable is to require decel to be at same rate as accel, ie a22=-a21.

Having done that, if you now specify the time you want the catch to happen, you are left with two unknowns td (time to start decelerating) and a21 (rate of acceleration). So you can solve the problem.

PS: you can see from your graph that the problem has infinitely many solutions, as the point of inflexion can be anywhere between the start and finish point. The earlier (later) it is, the higher (lower) the initial acceleration and the lower (higher) the deceleration.

8. Aug 2, 2015

### TaurusI76

Thanks Andrew for clearing that up. I was suspecting that I had too little known values to solve it.
However, in the simulation that I use this, I define the acceleration and deceleration rates. The cars have a max acceleration and deceleration and they use 'default' acceleration/deceleration values. Those are defined as 'comfortable' acceleration/deceleration values that you would use when driving normally (not leaving skid marks on the road or so ;) ). So fixing the acceleration/deceleration values can be done. And it makes sense to do make acceleration and deceleration equal.

So if in my case I would specify the rate of acceleration (a21), could I then find out the time that the catch up happens? Because that is what I was trying to figure out.
Or does it only work the way you described (specifying the time I want the catch up to happen)?

PS: what ARE those two equations now exactly? I've got a big mess in my head now...

Last edited: Aug 2, 2015
9. Aug 2, 2015

### andrewkirk

It doesn't have to go the way I wrote it. But you do have to specify two of the four unknowns that I listed. So having specified the rate of accel (a21) you now need to specify one of the other three: tc, td or a22.

To see why you have to do that, consider the following two different ways to achieve the goal using a fixed a21, with unknown tc, td, a21:

(1) [the petrolhead approach] continue accelerating at a21 until very near Car1 and then brake very hard
(2) [the eco-friendly approach] accelerate at a21 for a shorter time, then stop accelerating but don't brake at all. Just take your foot off the accelerator and allow the car to slow down on its own under the effects of friction and air resistance.

Both will achieve the final goal but 1 will achieve it earlier and will spend a larger proportion of the time accelerating (plus burn more fuel, use up the brake pads and the brake discs more, stress the engine and the passers-by more).

10. Aug 2, 2015

### TaurusI76

Yes, I eventually want to cover that with different driver profiles (the whole thing will be used in a video game). But since the accelerations are always defined (default would be equal acceleration and deceleration, 'eco-friendly' driver would be determined by how big the deceleration from friction/air resistance is (and that defines how long/fast it accelerates first), and 'agressive' driver would be defined by the max deceleration value), I should be able to calculate it.

But back to the equations:
• Say I have a default acceleration value that I use (ac2) and say I use the same deceleration value.
• I know how fast car 2 is going initially (vc2i).
• I know how far behind car 1 I am at t0.
• I know car 1's initial speed (vc1i)
• I know car 1's acceleration (ac1) (if there is any).
What I don't know are td, tc. And also, since I don't know WHEN the catch up will happen, I don't know how fast car 1 will be going by then (vc1f) (if it's not traveling at a constant speed, which would be the easier case). So I don't know how big of a gap (dgap) to leave.

How would I tackle these unknowns? I seem to be stuck with my way of calculating (see above). There's a piece/connection/substitution in there I'm just not getting. Could you point me in the right direction?

11. Aug 2, 2015

### andrewkirk

OK, it wasn't clear before - perhaps I missed it - that you wanted the final gap to be a variable that depends on the final velocities. I presume you want to apply the 3-second rule - to always drive at least 3 seconds behind the car in front. That is very commendable. I wish more drivers would follow that, instead of tailgating!

So, as you point out, that is an additional unknown.

I suggest you first identify practical limits: the maximum acceleration and the maximum deceleration. The latter will be much bigger than the former. You can also specify the maximum speed, which will be determined by laws and the caution of the driver, if it is on a public road, and by the physics of the car, together with the caution of the driver, if it is on a race track.

In most cases what happens is that Car2 accelerates to its maximum speed that the driver is comfortable with, then stops accelerating, maintains that speed until close to Car1 and then starts decelerating. If they want to frighten the driver of Car1 they will use option 1 (come up close and then brake hard). More usually they will use option 2 (take foot off the pedal and coast up to where the gap is right). From what little I know of video games, Option 1 is likely to be preferred.

To use this more lifelike approach, you need to specify the maximum comfortable speed v2max, the rate of accel a21 and the rate of decel a22. You will have another unknown, which is the time that acceleration stops (call it ta), as that is no longer the same as the time td that decel starts. But that is easily removed because you have a third equation that says accel stops when you reach max speed, and you know the acceleration rate so you can figure out that time. So now you have unknowns tc, td remaining and two equations.

So proceed as follows:
1. Write out ta as a function of v21, a21 and v2max
2. Write the final speed of Car2 as a function of v21, a21, ta, a22, td, tc and equate it to the final speed of Car 1 as a function of v11, a1, tc.
3. Write the final distance between the two cars, dgap, as the difference between the two distances travelled, which are functions of (v11, a1, tc) and (v21, a21, ta, a22, td, tc) respectively.
4. Write out the equation for the final gap dgap in terms of the final velocities, which are in turn expressed in terms of v1, a1 and tc. I suggest
$$d_{gap}=\frac{v_{11}+t_c a_1}{3\textrm{ seconds}}$$

You have four equations and the unknowns are ta, td, tc, dgap. So you can solve the system. Start by substituting from equation 1 into equations 2 and 3 to eliminate ta. THen equate equations 3 and 4 to eliminate dgap. You are left with two equations in two unknowns tc, td. Solve for them, then substiitute into eqns 1 and 4 to get dgap and ta.

12. Aug 3, 2015

### TaurusI76

How does tc fit into the final speed of car 2 function? I think that's the only part I don't get about your procedure.
I got: vf = v21 + a21 * ta + a22 * td ... so what do I do with tc here?

13. Aug 3, 2015

### andrewkirk

vf = v21 + a21 * ta + a22 *( tc- td )

14. Aug 3, 2015

### Staff: Mentor

@andrewkirk: I don't think it helps to introduce additional complications like a maximal velocity as long as the easier case without them is not solved yet.

I expected the accelerations to be known - that leaves a well-defined problem.

15. Aug 3, 2015

### TaurusI76

@mfb: you are right, the accelerations are known. And BTW, I think my initial question was a bit unclear. I should have asked not only if there is a solution, but what that solution is (because that's what was unclear to me as well).
But the max speed is ok, that's a variable I already have in my simulation and will need to put in anyway.

@andrewkirk:
So I've got
1. ta = (v2max - v21) / a21
2. v2final = v1final
1. v2final = v21 + a21 * ta + a22 * (tc - td)
2. v1final = v11 + a1 * tc
3. dgap = d1 - d2
1. d1 = v1 * tc + 0.5 * a1 * tc2
2. d2 = v21 * tc + 0.5 * a21 * ta2 + 0.5 * a22 * (tc - td)2
4. dgap = (v11 + a1 * tc) / 3
Now, ta I can calculate right away from the data I've got, so substitution is no problem here.
It's the solving for tc and td I'm struggling with now.
I've got
v21 + a21 * ta + a22 * (tc - td) = v11 + a1 * tc
and
(v11 + a1 * tc) / 3 = (v1 * tc + 0.5 * a1 * tc2) - (v21 * tc + 0.5 * a21 * ta2 + 0.5 * a22 * (tc - td)2)
(ta not even substituted yet - and I hope I did not make any mistake in the formulas)
Do I have to rearrange the equations to get tc and td separated from the rest?

16. Aug 3, 2015

### andrewkirk

Call your two new equations (i) and (ii). I suggest that next you rearrange equation (i) to express $t_c$ in terms of $t_d$ (unknown) and a bunch of other variables, all known. Then substitute that expression for $t_c$ into (ii) and you will get a quadratic equation in $t_d$ (unknown) with all other variables known. You can then use the formula for solutions to a quadratic equation to find $t_d$. Once you have that, you can calculate $t_c$ from (i).

Note that the quadratic formula will give you one, two or no solutions. If there are none, it means (either you've made a mistake or) there is no solution possible - ie Car2 cannot catch Car1. If there are two, you need to test both solutions by reinserting them into the original equations to see if they work, as it is possible that one of them won't (eg negative values of $t_d$ are not realistic as they imply reversing the flow of time). If only one works, you select that. If both work you can arbitrarily select one, eg the smallest one, which gives the quickest catch. That testing and selection process can be programmed into your game code.

17. Aug 4, 2015

### TaurusI76

That gives me one hell of a long formula! Is that supposed to be that long? (Because the equation for $t_c$ = (...) already is a long equation that I have to substitute in a number of places)

Also, I struggle to find a quadratic formula in the form of ax2 + bx + c = 0. $t_d$ is all over the place, and - if squared - only in conjunction with other variables...

I'm sorry if it's more an algebra question than a physics question now.

18. Aug 4, 2015

### Staff: Mentor

With new variable names on purpose because I find the old ones confusing:
Let $p_x, v_x, a_x$ be initial position, velocity and (constant) acceleration of car X. Let $d$ be the gap we want to keep.
Let $p_y, v_y, a_1, a_2$ be initial position, velocity and acceleration of car Y, where $a_1$ is acceleration in the first phase and $a_2$ in the second.
Let $t_1, t_2$ be the time spent in the acceleration and deceleration phase, respectively.

The position of car X after both phases is then given by
$P_x = p_x + v_x (t_1+t_2) + \frac{1}{2} a_x (t_1+t_2)^2$
Car Y is at
$P_y = p_y + v_y (t_1+t_2) + \frac{1}{2} a_1 t_1^2 + a_1 t_1 t_2 + \frac{1}{2} a_2 t_2^2$
We want $P_x = P_y + d$, but let's examine speed first:

$V_x = v_x + a_x (t_1+t_2)$ and $V_y = v_y + a_1 t_1 +a_2 t_2$
Those are equal. This allows to solve for one time:
$t_1 = e t_2 + f$ with some constants e and f.
Plugging that into the equation for position gives a quadratic equation in $t_1$. Not that nice, but still reasonable.
It might help to introduce new variables for $p_x-p_y-d$, $v_x-v_y$ and $a_x-a_1$.

19. Aug 4, 2015

### TaurusI76

How did you get to that? What are e and f made up of?
When I solve for $t_1$ I end up with $t_1$ = (-$a_x$ $t_2$ + $a_2$ $t_2$ - $v_x$ + $v_y$) / ($a_x$ - $a_1$)

20. Aug 4, 2015

### Staff: Mentor

It is a linear equation, there have to be constants e and f such that the equation is true.
Using your solution,$$e=\frac{a_2-a_x}{a_x-a_1}$$ and $$f=\frac{v_y-v_x}{a_x-a_1}$$
If you keep e and f instead of those fractions it makes the following steps much easier.

The solutions for e and f are not surprising, by the way. f is the time we have to spend to get rid of the initial speed difference, and e is related to the fraction of time spent afterwards in the two parts - which depends on the ratios of acceleration to braking, both times with the acceleration of the other car subtracted.