# Thread: finding the min distance between two vectors

1. ## finding the min distance between two vectors

Hi there,
Im trying to find the minimum distance(sum of their radii) between two circles.
The circles have position vectors a radius and a velocity vector.

i can find the minimum(s) distance using Pythagoras and a loop. but this is costly i would much prefer to use some sort of differentiation.

b=(x1+Vx1*t)-(x2+Vx2*t)
c=(y1+Vy1*t)-(y2+Vy2*t)

Best regards,
Mark

2. ## think iv done it in one plane at least

a=x1
b=vx1
c=x2
d=vx2
t= time

e = (a+bt)-(c+dt)
e² = (a+bt)-(c+dt)* (a+bt)-(c+dt)

Multiply out

-2abt + 2ac + 2adt -a2 + 2bct + 2bdt2 -b2t2 -2cdt -c2 -d2t2 + e = 0

Rearrange

2bdt^2 - b2t^2 - d2t^2

-2abt + 2adt + 2bct – 2cdt

-a2 - c2 + 2ac+ e

= 0

Factorise

(2ab- b² - d²)t²

-2t(ab + ad + bc - cd)

-a² - c² + 2ac + e

This looks like a quadratic since if we remove all known variables we get

t² - 2t +c

Therefore we can solve using the x = (-b +- root(b² -4ac))/2a

Let x=t
Let a=A (a, b, d) = (2ab- b² - d²)
Let b=B (a, b, c, d) = (2(ab + ad + bc – cd))
Let c=C (a, c, e) = -a² - c² + 2ac + e

solve this for each plane we need to consider and find the closest positive time to zero.

3. ## done

iv done it!!

generalising the above forumula with 3d vectors

gives me the desired result

best regards
mark