I have a circle $C$ with radius $r$ and a set of finite points $P=\left \{ p_1,p_2,\ldots,p_n \right \}$ are identified external to the circle $C$. These points may lie on the exterior or the interior or on both sides of the circle. There is another set of points $Q=\left \{ q_1,q_2,\ldots,q_n \right \}$ that is identified, where all the points lie on the circle.
Now I would like to rotate the circle $C$ such that the sum of squares of the Euclidean-distances $\sum_i^nd(p_i,q_i)^2$ is minimized, where $d(.)$ indicates the Euclidean-distance.
Note that both $p_i$ and $q_i$ are 2-d coordinates in real space. What is the angle of optimal rotation, in either a clockwise or anti-clockwise direction that minimizes these sums of Euclidean distances?
Take $C$ centered at the origin, and let $p_i = (R_i \cos \phi_i, R_i \sin \phi_i)$ and $q_i = (\cos \psi_i, \sin \psi_i)$. Say we rotated the circle by an angle $\theta$. Then you want to minimize the sum
$\sum_{i=1}^n (R_i \cos \phi_i - \cos( \psi_i + \theta))^2 + (R_i \sin \phi_i - \sin (\psi_i + \theta))^2$
$= \sum_{i=1}^N R_i^2 + 1 - 2R_i(\cos \phi_i \cos (\psi_i + \theta) + \sin \phi_i \sin(\psi_i + \theta))$
$ = \sum_{i=1}^n R_i^2 + 1 - 2R_i \cos(\theta +\psi_i - \phi_i)$
The above sum is minimized when the sum $\sum_{i=1}^n R_i \cos(\theta + \psi_i - \phi_i)$ is maximized.
Rewrite the sum $\sum_{i=1}^n R_i \cos(\theta + \psi_i - \phi_i)$ as $A cos(\theta + \delta)$ by noting it is a linear combination of cosines with the same frequency $\theta$ but different phase shifts $\psi_i - \phi_i$. Find $\delta$ from the $\psi_i - \phi_i$'s and $R_i$'s, then pick $\theta$ to maximize.