The three points form a triangle, as in the figure below:
![enter image description here](https://i.stack.imgur.com/Nyaoc.png)
You know the coordinates of the three vertices: $H(x_H,y_H)$, $A(x_A,y_A)$, and $T(x_T,y_T)$. The goal is to compute the angle between $\vec{AT}$ and $\vec{AH}$. I write these as vectors because you want an oriented angle, starting from the segment $\vec{AT}$ and increasing counterclockwise towards $\vec{AH}$.
The derivation below will result in an angle in the range $0 \le \theta < 360^\circ$. You can adjust the range to $-180^\circ \le \theta < 180^\circ$ by simply subtracting $180^\circ$ from the value we'll compute below.
We'll obtain the angle by making use of the dot and cross products of the vectors $\vec{AT}$ and $\vec{AH}$ to find the values of $\cos\theta$ and $\sin\theta$, respectively. The dot product between two vectors in $\mathbb{R}^2$ is a number which can be computed in two ways:
$$
\vec{a}\cdot\vec{b} \equiv a_x\,b_x + a_y\,b_y = |\,\vec{a}\,|\,|\,\vec{b}\,|\cos\theta
$$
Similarly, the cross product between two vectors in $\mathbb{R}^2$ is also a number which can be computed in two ways:
$$
\vec{a}\times\vec{b} \equiv a_x\,b_y - a_y\,b_x = |\,\vec{a}\,|\,|\,\vec{b}\,|\sin\theta
$$
Dividing the result from the cross product by the result for the dot product, we can compute $\tan\theta$:
$$
\tan\theta \equiv \frac{\sin\theta}{\cos\theta} = \frac{a_x\,b_y - a_y\,b_x}{a_x\,b_x + a_y\,b_y}
$$
Note that we can't perform that division when $\cos\theta$ (the denominator) is zero, that is, when $\theta = 90^\circ$ or when $\theta = 270^\circ$. Now for the actual computation.
Let
$$
(\, a_x \,,\, a_y \,) = \left(\,x_T-x_A \,,\, y_T-y_A \,\right)
$$
$$
(\, b_x \,,\, b_y \,) = \left(\,x_H-x_A \,,\, y_H-y_A \,\right)
$$
$$
s = a_x\,b_y - a_y\,b_x
$$
$$
c = a_x\,b_x + a_y\,b_y
$$
Then,
$$
\theta = 0^\circ
\quad\mbox{if}\quad
s = 0
\quad\mbox{and}\quad
c > 0
$$
$$
\theta = 90^\circ
\quad\mbox{if}\quad
s > 0
\quad\mbox{and}\quad
c = 0
$$
$$
\theta = 180^\circ
\quad\mbox{if}\quad
s = 0
\quad\mbox{and}\quad
c < 0
$$
$$
\theta = 270^\circ
\quad\mbox{if}\quad
s < 0
\quad\mbox{and}\quad
c = 0
$$
Now let
$$
\theta_0 = \arctan\left|\frac{s}{c}\right|
\quad\mbox{if}\quad
c \ne 0
$$
Then,
$$
\theta = \theta_0
\quad\mbox{if} \quad s > 0
\quad\mbox{and}\quad c > 0
$$
$$
\theta = 180^\circ - \theta_0
\quad\mbox{if} \quad s > 0
\quad\mbox{and}\quad c < 0
$$
$$
\theta = 180^\circ + \theta_0
\quad\mbox{if} \quad s < 0
\quad\mbox{and}\quad c < 0
$$
$$
\theta = 360^\circ - \theta_0
\quad\mbox{if} \quad s < 0
\quad\mbox{and}\quad c > 0
$$
The case when both $c = 0$ and $s = 0$ cannot happen unless the three points $A$, $T$, and $H$ coincide. As I said at the top, this results in $0 \le \theta < 360^\circ$ but you can adjust the range to $-180^\circ \le \theta < 180^\circ$ by subtracting $180^\circ$ from the angle computed above.
If I understand you right, then this may help, though it is far from a complete formula:
If we consider that a triangle is formed by the centre point, the point of intersection and the centre of the top line cd, and that the angle of the line is measured from that centre point, then the length of the line is the hypotenuse of an equilateral triangle formed by these three points.
If we now assume that the height of the rectangle is the adjacent, we can calculate the length of the hypotenuse using trigonometry as h = a / cos(t) where t is the angle of the line and o is half the rectangle's height. (Depending on software you may need to take an absolute value.)
We can repeat this formula with the width of the rectangle using cosine, hence the hypotenuse according to the width is h = o / sin(t) where a is half the rectangle's width.
The actual length of the hypotenuse must be whichever of these two values is lower.
There are other methods, such as calculating the intersection point of the line with each line that makes up the rectangle and taking the closest to the point of origin, but I think this is the more efficient.
Best Answer
Let $X$ be the external point. Let $P$ be the center of the circle. Let $Q$ be a point of tangency. Then triangle $\Delta PQX$ is a right triangle. If we let $\theta$ be the angle that $PX$ makes with the horizontal, then the angle of the tangent point with the horizontal is $\theta + \angle XPQ$ and $\theta - \angle XPQ$ respectively. Consequently, the angle that the tangents make with the vertical will also be $\theta \pm \angle XPQ$.
In the figure above, the green angle would be the angle give by $\theta + \angle XPQ$.
If $X = (x_2, y_2)$ and $P = (x_1, y_1)$ then $\theta = \arctan\left(\frac{y_2 - y_1}{x_2 - x_1}\right)$.
If you want the heading to the tangent point, then you will want the red angle (there is another angle for the lower tangent which I have not labelled, it is given analogously) which will be $90^{\circ} - (\theta - \angle XPQ)$.
If you want the angle the tangent makes with the vertical, you will want the blue angle (or the supplement of the blue angle) which is equal to the green angle, $\theta + \angle XPQ$.
You may have to tweak a bit to make sure that everything works out in all quadrants, but this is the basic idea.
Edit If you want $\angle FXQ$ as defined in your comment, then it is simple. Draw a vertical line intersecting $X$. Then the tangent cuts through the vertical line and the $y$ axis as parallel lines. $\angle FXQ$ is then given by the blue angle.