How to find an angle to rotate vector to align with a point 
We know the value of point $T$ is $(x, y)$.
From $(0, 0)$ there is a line to point $p$ (I'll call this line $D$) with length $d$ and at that point, there is a vector (I'll call it $V$) that has an angle $\theta$ with $D$.
The problem is how to find an angle $\theta'$ that makes $V$ align with $T$?
I've tried to calculate $\theta'$ by

*

*Calculate $l = \text{distance from T to (0, 0)}$

*Find $r$ by using law of cosine $r = d\cos{\theta} \pm \sqrt{l^2 - d^2\sin{\theta}}$

*Using $r$ to create a circle from point $T$ with radius $r$ and find an intersection point $p'$ with circle from $(0, 0)$ with radius $d$

*Calculate the distance between $p'$ and $p$ and use it as a base of a triangle that has point $p$, $p'$ and $(0, 0)$ as a vertex

*We can calculate $\theta' = 2\arctan{\frac{0.5 \times \text{triangle_base}}{d}}$

Is there a simpler way to solve this problem?
 A: The equation of the line before rotation is
$ r(t) = D + t V $
In terms of coordinates, this is
$ r(t)= (D_1, D_2) + t (V_1, V_2) $
This is the vector equation of the line.  Define the perpendicular to the line by
$N = (-V_2, V_1) $
then it follows that the algebraic equation of the line is
$ N \cdot ( r - D ) = 0 $
After rotation by an angle $\theta'$ counterclockwise, the image of a point $r$ is $r'$ given by
$ r'(t) = R(\theta') r $
where
$R(\theta') = \begin{bmatrix} \cos(\theta') && -\sin(\theta') \\ \sin(\theta') && \cos(\theta') \end{bmatrix} $
From this, it follows that
$ r = R^{-1}(\theta') r' = R^T (\theta') r' $
Hence, the equation of the rotated line is
$ N \cdot ( R^T r' - D ) = 0 $
Now we want point $ Q  $ (I've changed it from $T$ to $Q = [Q_1, Q_2]$) to lie on this rotated line.  Substitute $r' = A$
$ N \cdot ( R^T Q - D ) = 0 $
Everything here is known except $\theta'$.  Expanding the above equation,
$ [-V_2, V_1]\cdot (  [ Q_1 \cos(\theta') + Q_2 \sin(\theta') , - Q_1 \sin(\theta') + Q_2 \cos(\theta') ]^T - [D_1, D_2] ) = 0 $
Collecting terms, this is of the form
$ A \cos(\theta') + B \sin(\theta') = C $
where
$ A = -  V_2 Q_1 +  V_1 Q_2 $
$ B = - V_2 Q_2 - V_1 Q_1 $
$ C = -V_2 D_1 + V_1 D_2 $
And this equation has two solutions
$ \theta' = \phi \pm \cos^{-1} \left( \dfrac{ C }{\sqrt{A^2 + B^2}}\right) $
where $ \phi $ is the angle such that $ \cos(\phi) =\dfrac{ A }{\sqrt{A^2 + B^2}}$,  $\hspace{4pt}\sin(\phi) = \dfrac{ B}{\sqrt{A^2 + B^2}} $
