Position of the first circle is described as
x1 = x1_0 + vx1 * t
y1 = y1_0 + vy1 * t
where x10
is initial x-coordinate, vx1
is x-component of velocity vector, t
is time.
Make similar expression for the second circle center, build expression for squared distance and find time when squared distance becomes equal to 4R^2
(for equal radii) – if solution exists at needed time interval, it is the moment of circles’ collision.
In your designations (seems you have equal velocities):
RSum = circleA.radius + circleB.radius
//position changes
dax = (circleA.pathx - circleA.x)
day = (circleA.pathy - circleA.y)
//normalize components
lenA = Sqrt(dax * dax + day * day)
dax = dax / lenA
day = day / lenA
//position vs time
ax = circleA.x + dax * t
ay = circleA.y + day * t
and similar for B
circle
Now make distance equation, substitute ax, bx, ay, by
expressions and solve it for unknown t
(quadratic equation, might have 0,1,2 roots)
(ax - bx) * (ax - bx) + (ay - by) * (ay - by) = RSum * RSum
or
(circleA.x + dax * t - circleB.x - dbx * t) * ....
6
solved JavaScript – determine if two circles will intersect along their path