Question:
Given the line
$ \ell(t) = r_0 + t \ u $
I want to rotate it about point $P_0$, such that it becomes tangent to the ellipse
$ (r - C)^T Q (r - C) = 1$
where $ r = [x,y]^T$, $C$ is the center of the ellipse, and $Q$ is $2 \times 2 $ symmetric positive definite matrix.
My attempt:
Rotation of the given line about $P_0$ by an angle $\theta$ produces the new line
$ L(t) = P_0 + R (\ell(t) - P_0) = P_0 + R ( r_0 - P_0 + t \ u ) $
Let $n$ be perpendicular to $u$ , then $ R n $ is the normal vector of the rotated line.
The point $r_1$ on the ellipse where the gradient is parallel to this normal vector of the rotated line satisfies
$ Q (r_1 - C) = K R n $
It can be easily shown that
$ K = \dfrac{1}{\sqrt{ n^T R^T Q^{-1} R n } } $
Hence
$ r_1 = C + \dfrac{ Q^{-1} R n }{ \sqrt{ n^T R^T Q^{-1} R n }} $
Now we want this point to be on the line, therefore, we want
$ ( R n )^T ( r_1 - [ P_0 + R ( r_0 - P_0) ] ) = 0 $
Substituting $r_1$ gives
$ (R n)^T ( C - P_0 - R (r_0 - P_0) ) + \sqrt{ n^T R^T Q^{-1} R n } = 0 $
Therefore, we want to solve
$ n^T R^T Q^{-1} R n = \bigg( (R n)^T (C - P_0) - n^T (r_0 - P_0) \bigg)^2 $
Define $w = R n$ , and $ V = C - P_0 $, and $ c_0 = n^T (r_0 - P_0) $
Then the above equation is
$ w^T (Q^{-1} - {VV}^T ) w + 2 c_0 w^T V - c_0^2 = 0 $
We can assume that $n$ is a unit vector, then so is $w$, i.e.
$ w^T w = 1 $
Solving these two equations gives $w$. Now we can find $\theta$ which related the rotated vector $w$ to the original vector $n$.

