# 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

-
Your question is a little bit unclear. What do you mean by "intersect the circle at $90^{\circ}$ to the center point"? If you could provide some form of diagram, that would be of great help. –  EuYu Oct 1 '12 at 22:15
Essentially I mean I need to get the angle to a tangent on the circle from North (0*)... I.E. I need the angle to the tangent point from X, in terms of North (0* vertical). I.E., if the tangent was directly to the right, it would be 90*. –  Christian Stewart Oct 1 '12 at 22:22
@ChristianStewart In the OP you should say "tangent to the circle" because the way it is put is unclear. Also, which tangent? X has two tangents to the circle, one "above" one "below" –  user39572 Oct 1 '12 at 22:25
So essentially, given a circle and some point, you want to find the two tangents from the point to the circle. More specifically, you want the angle of the tangents to the vertical? –  EuYu Oct 1 '12 at 22:26
Sorry for being unclear. it's a bit difficult to explain. There are two tangents to the circle, I'd like to be able to choose either one. The angle I need is from vertical (so a undefined slope that passes through X) to either one of the tangents. –  Christian Stewart Oct 1 '12 at 22:37

## 1 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.

-
What do you mean about east or west? Assuming 90* is east, 180* would be west, and 360* would be 0* –  Christian Stewart Oct 1 '12 at 22:48
Ah I see. I thought you wanted the angle in terms of $\theta^\circ$ West of North, etc. $180^\circ$ would be south right? –  EuYu Oct 1 '12 at 22:51
Consider it like a compass heading to the tangent point. –  Christian Stewart Oct 1 '12 at 22:52
What an incredibly well written answer. One quick tweak: what I meant by the heading angle is this: Draw a vertical line that intersects X. Place a point (name it F) above X on that line. The angle I need is angle PXQ (the obtuse angle) –  Christian Stewart Oct 1 '12 at 23:01
Do you mean PXF? –  EuYu Oct 1 '12 at 23:09