Distance between a point and a circle circumference given angle from point

Let us assume that I have a circle with radius $r$ and centre $C$ and a point $P$. How can I find the length of the line segment starting from $P$ with a specific angle $\theta$, ending on the circumference of the circle (assuming that I chose the angle so that is the case). If the line intersects twice (that is if it is not a tangent), I want the distance to the closest point.

I know that I can easily find the angle and distance between the points, but I am not sure how it will help me. I also assume that the approach consists of finding the point where the line and circle intersects in order to find the distance between the points.

UPDATE: $P$ can be where ever in the plane as long as it is outside the circle. $\theta$ is measured according to the x-axis (I'm not sure that is a very accurate description, ask if you do not understand)

• How do you define the $\theta$ angle the line makes with the circumference, and are there conditions on $P$? – Parcly Taxel Nov 4 '16 at 12:15
• Presumably you are given something like $d(P,C)$? If $X$ is the point on the circle then however you define $\theta$ you can use it to compute $\angle CXP$, no? So you can invoke the law of cosines. – lulu Nov 4 '16 at 12:15
• I am not sure I get what you are asking, lulu. But it is no problem for me finding the (euclidean) distance between the centre of the circle and the point.... Oh you updated your question. I don't have X, that is my problem. The angle is from the point not on the circl.e – playdoe Nov 4 '16 at 12:20
• Oh, I think i was just being stupid, I see what you mean now. I will check it out, and if it makes sense for me I will accept your answer. – playdoe Nov 4 '16 at 12:31

On an $x,y$ Cartesian plane, suppose we are given the coordinates of a point $C$, the radius $r$ of a circle around $C$, the coordinates of a point $P$ outside the circle, and a ray $\overrightarrow{PQ}$ starting at $P$ at an angle of $\theta$ clockwise from the $x$-axis. (The coordinates of $Q$ need not be known; it is used here just as a way to name a particular ray starting at $P$.)

Find the distance $d$ from $P$ to $C$ and the direction $\theta_0$ (clockwise from the $x$-axis) of the ray $\overrightarrow{PC}$ from $P$ through $C$. Compute the angle $\alpha$ between the rays $\overrightarrow{PQ}$ and $\overrightarrow{PC}$; it is $\lvert \theta - \theta_0 \rvert$, $\lvert \theta - \theta_0 + 2\pi \rvert$, or $\lvert \theta - \theta_0 - 2\pi \rvert$, whichever is smallest.

If $\alpha \geq \frac\pi2$ then there is no intersection, so we're done. In all of the discussion below, assume that $\alpha < \frac\pi2$.

If $M$ is the point on ray $\overrightarrow{PQ}$ closest to $C$, the triangle $PMC$ is a right triangle with a right angle at $M$ and the angle $\alpha$ at $P$. Therefore the distance $CM = d \sin \alpha$ and the distance $PM = d \cos\alpha$. (Note that we compute all of this without needing to find the coordinates of $M$.)

If $d \sin \alpha > r$ then there is no intersection. If $d \sin \alpha = r$ then the ray $\overrightarrow{PQ}$ is tangent to the circle, $M$ is the point of tangency and is one endpoint of the line segment, and the distance $PM$ is $d \cos \alpha$.

If $d \sin \alpha < r$ then ray $\overrightarrow{PQ}$ intersects the circle in two points. One of these points is between $P$ and $M$; call that point $X$. Then $XMC$ is a right triangle with hypotenuse $XC = r$ and leg $CM = d \sin \alpha$; the length of the other leg is therefore $XM = \sqrt{r^2 - d^2 \sin^2 \alpha}$. Therefore $$PX = PM - XM = d \cos \alpha - \sqrt{r^2 - d^2 \sin^2 \alpha},$$ which is the distance we were to find.

The equation of the line can be written $$\mathbf{X}(t) = \mathbf{P} + t(\cos\theta, \sin\theta)$$ If $\mathbf{P} = (a,b)$, then this becomes \begin{align} x &= a + t \cos\theta \\ y &= b + t \sin\theta \\ \end{align} Suppose the circle center is at $\mathbf{C} = (h,k)$ and its radius is $r$. Then it's equation is $$(x-h)^2 + (y-k)^2 = r^2$$ Substitute $x$ and $y$ from above into this equation, and you'll get a quadratic in $t$. Find its real roots $t_1$ and $t_2$ (if any). Then the intersection points are $\mathbf{P} + t_i(\cos\theta, \sin\theta)$ for $i=1,2$.