# Calculating if two objects will come within a given distance

Tags:
1. Feb 21, 2016

### ferret_guy

I am having trouble calculating if two objects with initial positions and velocity vectors will come within a given distance of one another and if so calculating where the closest approach is. Can anyone point me in the right direction?

My initial thoughts are that both are linear functions where:
$d=tv$
$y=tv(cos \theta )+y_{i}$
$x=tv(sin \theta)x_{i}$
The distance is:
$d = \sqrt {( {x_1 - x_2 })^2 +( {y_1 - y_2 })^2}$
Expanding to:
$d = \sqrt {( {(tv_{2}sin \theta_{2}+x_{2_{i}})- (tv_{1}sin \theta_{1}+x_{1_{i}}) })^2 +( {(tv_{2}cos \theta_{2}+y_{2_{i}})- (tv_{1}cos \theta_{1}+y_{1_{i}}) })^2 }$
My next thought is to take the derivative with respect to time to find the turning point of the graph and thus the closest approach to one another. If the turning point is when t is negative then t0 is the closest approach and if it is greater than t0 then the value is the closest approach

Last edited: Feb 21, 2016
2. Feb 21, 2016

### drvrm

explain your problem with proper velocities?

3. Feb 21, 2016

### ferret_guy

I am writung some software for quadcopters and I need to be able to see if they will come within some distance of one another I think the best solution is to just find the closet approach. Only need a 2d solution as they are all on the same plane

4. Feb 22, 2016

### ferret_guy

After using wolfram mathematica I have found that the differential is:
$\left(\frac{2 \left(v_2 \sin \left(\theta _2\right)-v_1 \sin \left(\theta _1\right)\right) \left(-x_{1_i}+x_{2_i}-t v_1 \sin \left(\theta _1\right)+t v_2 \sin \left(\theta _2\right)\right)+2 \left(v_2 \cos \left(\theta _2\right)-v_1 \cos \left(\theta _1\right)\right) \left(-y_{1_i}+y_{2_i}-t v_1 \cos \left(\theta _1\right)+t v_2 \cos \left(\theta _2\right)\right)}{2 \sqrt{\left(-x_{1_i}+x_{2_i}-t v_1 \sin \left(\theta _1\right)+t v_2 \sin \left(\theta _2\right)\right){}^2+\left(-y_{1_i}+y_{2_i}-t v_1 \cos \left(\theta _1\right)+t v_2 \cos \left(\theta _2\right)\right){}^2}}\right)$

and solving for when d/dt =0 gives:
$\frac{v_1 \left(-\sin \left(\theta _1\right)\right) x_{1_i}+v_2 \sin \left(\theta _2\right) x_{1_i}+v_1 \sin \left(\theta _1\right) x_{2_i}-v_2 \sin \left(\theta _2\right) x_{2_i}-v_1 \cos \left(\theta _1\right) y_{1_i}+v_2 \cos \left(\theta _2\right) y_{1_i}+v_1 \cos \left(\theta _1\right) y_{2_i}-v_2 \cos \left(\theta _2\right) y_{2_i}}{v_1^2 \sin ^2\left(\theta _1\right)+v_2^2 \sin ^2\left(\theta _2\right)-2 v_2 v_1 \sin \left(\theta _1\right) \sin \left(\theta _2\right)+v_1^2 \cos ^2\left(\theta _1\right)+v_2^2 \cos ^2\left(\theta _2\right)-2 v_2 v_1 \cos \left(\theta _1\right) \cos \left(\theta _2\right)}$

and knowing that it only equals zero in one location I can solve for that point in time to find the closest distance and position of closest approach. Seems like there could be a better way, and if done in 3d would give even more ridiculous results. Is there a better way?

5. Feb 22, 2016

### drvrm

well suppose in the plane there are two vehicles each located by a position and velocity vector
say at r(1) and r(2) there velocity being v(1) and v(2) at time t=t(1);
i do not know but if you are sitting on one and observing the closest approach - why dont you apply a reverse velocity to your self as well as the other one- so you go to rest and the body (other) has a net velocity v(1) + v(2) a vector addition.
the distance between 1 and 2 is r= r(1)- r(2) a vector addition at t=t(1) initial time.
so if you analyse the motion of 2 with respect to 1 and minimize the distance as time advances ,i think you can get a way out...how do you feel about this approach?

6. Feb 22, 2016

### A.T.

As drvrm said, choosing the rest frame of one of the objects reduces the mathematical complexity of such problems.