I'm assuming the motion of the circles is linear. Let's say the position of circle A's centre is given by the vector equation Ca = Oa + t*Da
where
Ca = (Cax, Cay)
is the current position
Oa = (Oax, Oay)
is the starting position
t
is the elapsed time
Da = (Dax, Day)
is the displacement per unit of time (velocity).
Likewise for circle B's centre: Cb = Ob + t*Db
.
Then you want to find t such that ||Ca - Cb|| = (ra + rb)
where ra
and rb
are the radii of circles A and B respectively.
Squaring both sides:
||Ca-Cb||^2 = (ra+rb)^2
and expanding:
(Oax + t*Dax - Obx - t*Dbx)^2 + (Oay + t*Day - Oby - t*Dby)^2 = (ra + rb)^2
From that you should get a quadratic polynomial that you can solve for t (if such a t exists).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…