Rotation between two circles

circlescollision detectiongeometryrotations

I have the following collision detection problem that I am trying to solve. I am more of a programmer than a mathematician so please go easy on me!

I have two circles on a Cartesian plane defined by their centroids $(p_1, p_2)$ and their radii $(r_1, r_2)$. Circle 1 is rotated around the origin $O$. Circle 2 lies in the path of circle 1 as it is rotated around $O$. $p_1$ and $p_2$ do not intersect under this rotation (otherwise the solution I seek would be trivial).

I am trying to determine the rotation, $R$ around $O$ at which circle 1 will 'collide' with circle 2 (see the linked image). I can solve this iteratively (i.e. incrementally rotate circle 1 around the origin of the reference frame and test for intersection between circle 1 and circle 2). However, I would like to know if there is a closed form solution to this problem.

Linked image: https://www.dropbox.com/s/2nevu15hib1onf4/circ_rot.png?dl=0

Thanks in advance!

Best Answer

Use the law of cosines. If $\rho_i$ denotes the distance of $p_i$ from the origin, and you want the distance between the centres to be $r_1+r_2$, you need the angle bewteen the lines from the origin to the centres to form an angle $\theta$ that satisfies

$$ (r_1+r_2)^2=\rho_1^2+\rho_2^2-2\rho_1\rho_2\cos\theta\;, $$

and thus

$$ \theta=\arccos\frac{\rho_1^2+\rho_2^2-(r_1+r_2)^2}{2\rho_1\rho_2}\;. $$

Then you just need to calculate the angle originally formed by these lines and rotate by the difference of the two angles.