How much should I rotate P around O so that D points to T?
O is Origin, P is point rotating around origin. D is direction that we are pointing. T is the target.
To rotate P around O we have
$$ P' = \begin{bmatrix} X_O\\ Y_O\\ \end{bmatrix} + \begin{bmatrix} X_P - X_O\\ Y_P - Y_O\\ \end{bmatrix} \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \\ \end{bmatrix} $$
I have to find $\theta$ so that line $D'$ would cross $T$ and $P'$. but I'm lost here.
I also know this line equation from two points
$$ y-y_{1}={\frac {y_{2}-y_{1}}{x_{2}-x_{1}}}(x-x_{1}) $$
I thought I could put $P'$ and $T$ in this equation but then I would have two unknowns. I can't solve it further.
P.S: I actually need 3d solution but 2d answer is fine if it can be expanded to 3d.
Here is what I tried. for the slope of the line we have
$$ \tan(\theta) = m = \frac{y_2−y_1}{x_2−x_1} $$
If I put T and P'
$$ \theta = \arctan(m) = \arctan(\frac{Y_O+(X_P-X_O)\sin(\theta)+(Y_P-Y_O)\cos(\theta)−T_y}{X_O+(X_P-X_O)\cos(\theta)-(Y_P-Y_O)\sin(\theta)−T_x}) $$
Now that I have all the pieces $O, P, T$ how do I solve for $\theta$?

Write $r = \overline{OP}$, $d = \overline{OT}$. Then $r = \overline{OP'}$ as well, since $P'$ is a rotation of $P$ about $O$. Further, $\angle OPD = \angle OP'T = \theta$ (say). Write $\varphi = \angle P'TO$. Then by the law of sines, $$\sin\varphi = \frac{r\sin\theta}{d}.$$ Thus $\varphi = \sin^{-1}\left(\frac{r\sin\theta}{d}\right)$, and then \begin{equation*} \angle P'OT = \pi - \theta - \varphi = \pi - \theta - \sin^{-1}\left(\frac{r\sin\theta}{d}\right). \end{equation*} Thus one can determine $\angle P'OT$ from the given data; since $\angle TOP$ is fixed, we can also determine $\angle POP'$, which is what you need.