# Optimal rotation to align a circle with external points

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?

-
–  gt6989b May 1 '13 at 21:20
@gt6989b Maybe related, but are 'different' questions altogether ;) –  halms May 1 '13 at 21:21
I agree they are different, but someone looking at this for the first time, may be interested in a simpler version. –  gt6989b May 1 '13 at 21:23
@gt6989b ok. i now understand ur view point. that's true. –  halms May 1 '13 at 21:24
In my view it was very bad style to post this without providing the link that @gt6989b provided. The answers are almost the same; you wasted everyone's time by not alerting them to the connection; and you caused unnecessary confusion because the answers to the two questions now use conflicting variable names. –  joriki May 2 '13 at 1:59

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.

-
Note that you can get displayed equations by using double dollar signs instead of single dollar signs. That centres the equations and makes things like sums with limits look less cramped. To align the equal signs despite the centering, you can use \begin{align} and \end{align}, together with ampersands as alignment marks. –  joriki May 2 '13 at 2:03