# How to calculate the closing speed of two objects

I have the 2D positions and 2D velocity vectors of two objects. How do I calculate the closing velocity ? I want to get the closing speed.

Think of one jet tracks another jet with radar and you want to yield the closing speed, which is actually the distance-change / unit. (In this example Δmiles/h)

• Velocity1 + Velocity2 – jgallant Mar 13 '16 at 14:32
• Please clarify something: What do you mean exactly by closing speed? My guess would be that you want to get the speed of the distance-change between those two objects. Is that correct? – LukeG Mar 14 '16 at 14:18
• @LukeG correct. Think of one jet tracks another jet with radar and you want to yield the closing speed, which is actually the distance-change / unit. (In this example Δmiles/h) – Marco Mar 14 '16 at 17:51
• Thank you. Under that circumstances Samed's answer is indeed incomplete. It only yields correct results if the two jets would collide at some point with the current velocities. For a complete, general solution, please refer to my answer, which I tested for correctness. – LukeG Mar 14 '16 at 18:02
• @LukeG Check my edited answer, I'm not sure if I do something wrong but, as you can see my formula still works even if objects don't collide. – S. Tarık Çetin Mar 14 '16 at 21:06

You essentially have two lines with the equations:
$a(t)=a_0 + t*v_a$

$b(t)=b_0 + t*v_b$

where $a_0, b_0, v_a, v_b$ are vectors with the same dimension and unit (meters for $a_0$ and $b_0$ and meters per second for $v_a$ and $v_b$).

$a(t)$ and $b(t)$ are the positions of your objects at time $t$ (in seconds if using the units above).

Distance over time is calculated by subtracting the positions and taking the length of the vector:
$d(t)=\left|a(t)-b(t)\right|=\left|a_0-b_0+t*(v_a-v_b)\right|$

This has to be differentiated to get the closing speed (The multiplication used is the dot-product): $c(t)=d'(t)=\frac{(v_a-v_b)*((v_a-vb)*t+a_0-b_0)}{\left|(v_a-v_b)*t+a_0-b_0\right|}$

The value of $c(t)$ is a scalar.

You probably want the closing speed at t = 0 (i.e. now), so it can be simplified further:

$c(0)=d'(0)=\frac{(v_a-v_b)*(a_0-b_0)}{\left|a_0-b_0\right|}$

Unit of the result is the same as the components of the original velocity vectors. It is negative if the objects get closer to each other and positive if the distance increases. If you want it the other way around you have to multiply by -1.

$current closing speed=-c(0)=-\frac{(v_a-v_b)*(a_0-b_0)}{\left|a_0-b_0\right|}$

Note that this works for all dimensions.

Every matrix-/vector-math library will support all of the necessary operations. Depending on its design this can be written as a single line of code. However you may prefer to store $a_0 - b_0$ in a temporary variable.

In Pseudocode this may look like this

val tmp = a.position - b.position
return -((a.velocity - b.velocity).dot(tmp)/tmp.length)

• thx Luke for the detailed explaination – Marco Mar 13 '16 at 17:17

To find the relative velocity vector, you need to substract the vectors. The magnitude of that vector is your closing speed.

(Note that the operation inside the magnitude function of the third situation is a vectoral substraction, not a scalar one.)

Edit:

Assume initial positions are A and B, distance is dis, velocities are v(A) and v(B).

(As you can see, objects can never collide.)

Now, if we do this:

As you can see now, the c vector is the relative velocity.

Now, we can write these equations:

Also these:

Now, here is what you want in question:

As we wrote above, this yields to this:

Which eventually yields to:

Which is our relative velocity.

• I don't think this answer is correct. While it yields correct results for some basic cases it is definitely not correct for the general case, which, for my understanding, is what was asked here. The correct distant function is a hyperbola, which does not result in a constant closing speed, as your solution suggests. – LukeG Mar 14 '16 at 12:33
• @LukeG The closing speed is the magnitude of relative velocity of the object which is moving away, relative to the closing object. Relative velocity is found by this formula: Object B's velocity relative to Object A = (Object B's velocity) - (Object A's velocity). (Remember that velocity is a vector, so you need to do vectoral substraction.) – S. Tarık Çetin Mar 14 '16 at 13:55
• If the objects collide you are right and your solution works. But if they merely pass each other their distance does not change linear. In the general case, where the objects don't necessarily collides your solution is merely the asymptotic value of 'closingSpeed(t)'. – LukeG Mar 14 '16 at 14:07
• @LukeG I think you assume objects have accelerations, the OP said he has the velocity vectors, but he didn't mention about acceleration. – S. Tarık Çetin Mar 14 '16 at 16:42
• No, I did not take accelerations into account. Look at my answer where I derive the general formula in-depth using analytical methods. As I said, your formulas give correct results only if the objects collide. I made a excel sheet detailing this, I can upload it if you want to. – LukeG Mar 14 '16 at 16:55

Simple: Unlike the rest of these answers.

V1*sin(dir) - V2*sin(dir)

30*sin(090) - 40*sin(270) = 70

If you want the range, just add it in like so

Range-(30*sin(090) - 40*sin(270) = 70)

• It's completely unclear what you are trying to say. Please clarify what the variables/formulas are supposed to say. – LukeG Apr 8 '16 at 8:26
• Sorry about that. I made a quick graph to show you exactly what I mean. desmos.com/calculator/shjlof82kq – Daniel Strickland Apr 8 '16 at 8:49
• This is transparently incorrect. Let's choose angles so that the two objects are heading in opposite directions, 0 and 180, directly toward / away from one another. We'd expect the closing speed to be the sum of their speeds (positive or negative, depending on whether they're approaching or separating), but this formula will give a result of zero, claiming the distance between them is unchanging. – DMGregory Dec 23 '18 at 15:53