Get Angle to Tangent that Intersects Point I have a circle around a given point, call this point $(x_1, y_1)$. I know the radius of the circle around this point. I also have a second point $(x_2, y_2)$, that is a distance away, outside the radius of the circle.
I need a algebraic way through code to calculate the heading (angle from vertical) needed to intersect the circle at $90^\circ$ to the center point (I.E. get the angle of the tangent intersecting line 2) around the point $(x_1, y_1)$ from the second point $(x_2, y_2)$
A bit of background: Essentially the two points are GPS coordinates on a 2D map, I need to know the target heading to intersect the circle in order to follow its path around the center point.
Thanks!
Christian
Additional info:
P is the center of the circle, X is the arbitrary point, D is a known distance, R is the known radius, I need to find the tangent to the point X and the angle from North (straight up) to that tangent point from X.
The known info is R, D, Point X, Point P, and through math, the distance to wherever the tangent point is
 A: 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.
