# Tangents to a circle in 3D

I couldn't find this question asked for the 3D case; so here goes:

I have a circle given by the center $c=(x_c,y_c,z_c)$ and the normal $n=(x_n,y_n,z_n),||n||=1$.

Further, I have a point $p=(x_p,y_p,z_p)$ that is guaranteed to be in the same plane of the circle and also outside of the circle.

I am looking for a closed form for the two tangents from $p$ to the circle.

My idea is to get the formula for the circle from here Parametric Equation of a Circle in 3D Space?:

$\left(\matrix{x\\y\\z}\right)=c+r\cdot \cos(\theta)\cdot a+r\cdot \sin(\theta)\cdot b$

($a, b, r$ are known) and set it equal to the other required property:

$\left(\matrix{x-x_c\\y-y_c\\z-z_c}\right).\left(\matrix{x-x_p\\y-y_p\\z-z_p}\right)=0$

But I don't know where to go from there.

• The tangents are along the derivatives of the curve for parameter $\theta$. So the vector to the circle at parameter $\theta$ + real valued parameter * derivative evaluated at $\theta$. – mathreadler May 22 '17 at 13:39
• This leads me to $c+(r\cdot a\cdot \cos(\theta))+(r\cdot b\cdot \sin(\theta))+x\cdot (r\cdot b\cdot \cos(\theta) - r\cdot a\cdot \sin(\theta)) = p$, which I'm not sure if I can solve this for $\theta$ – Thomas B. May 22 '17 at 17:19
• Ignoring the tangency conditions for the moment, what would what you consider a “closed form” for a pair of lines in $\mathbb R^3$ look like? There’s no single non-parametric Cartesian equation that can do this. A parametric form seems possible since a pair of intersecting lines is a degenerate hyperbola. – amd May 22 '17 at 18:18
• @ThomasB: You have $x$ and $\theta$ to solve for. You can start at some initial values and then alternately solve for $x$ and $\theta$ or maybe fused solutions. I find it likely to converge very fast. Why is it important with a closed form? I would prefer a form where it is straight forward how to find a solution and also generalizes well to harder trajectories where an analytic solution is impossible. – mathreadler May 22 '17 at 18:40

From your last equation you could obtain $\theta$ (actually, you should find two solutions) and from that also the coordinates of the tangency points $t_1$ and $t_2$. But in practice this leads to complicated equations.

A simpler method could be the following: if $m=(p+c)/2$ is the midpoint of $pc$, subtract the cartesian equation of the sphere with center $m$ and radius $||m-p||$ from the equation of the sphere with center $c$ and radius $r$: the result is the equation of plane $\alpha$, perpendicular to line $pc$ and containing the tangency points.

The intersection of $\alpha$ with the plane of the circle, and with the sphere with center $c$ and radius $r$, will readily give the required tangency points.

EDIT.

We can simplify the equations by making a translation to make $c=(0,0,0)$. In that case the system of equations described above can be written as $$\cases{ p\cdot t=r^2\\ n\cdot t=0\\ t\cdot t=r^2 }$$ where $t=(x,y,z)$ is a tangency point. To solve this, we can make use of the fact that $p$ and $n\times p$ are two orthogonal vectors in the plane of the circle. There exist then two real numbers $\alpha$ and $\beta$ such that $$t=\alpha p+\beta(n\times p).$$ By substituting that into the equations one can readily find $\alpha=\rho^2$ and $\beta=\pm\rho\sqrt{1-\rho^2}$, where I set $\rho=r/||p||$. Finally, we can make the reverse translation and obtain the final formula: $$t=c+\rho^2(p-c)\pm\rho\sqrt{1-\rho^2}\,n\times(p-c), \quad\hbox{with}\quad \rho={r\over||p-c||}.$$

• Thank you very much! While I can understand what you mean, I think I'll have trouble expressing the solution within a single formula $(x_1,y_1,z_1)=...,(x_2,y_2,z_2)=...$ I had hoped that such a formula existed. – Thomas B. May 22 '17 at 17:24
• I tried to find a single formula with Mathematica and the result was VERY long and cumbersome. If you want, I can add it to my answer. But I think that a "step by step" approach would be simpler. – Aretino May 22 '17 at 18:13
• See my edited answer for a reasonably simple vector formula. – Aretino May 22 '17 at 22:16
• Outstanding! I did not expect such an elaborate answer when I asked the question here – Thomas B. May 23 '17 at 6:08

Translate everything by $-c$ so that the circle center goes to the origin and $p$ goes to $p'$. Now take the cross product of the vectors $n$ and $p'$, let $q$. Normalize $p'$ and $q$ to be unit vectors. Now the matrix $R$ formed by $p',q,n$ is a rotation matrix that applies the plane $oxy$ to the plane $op'q$ and the axis $ox$ to $op'$.

Take the transpose of this orthogonal matrix, which is its inverse and perform the inverse rotation.

You now have a circle in the plane $oxy$, centered at the origin, and a point $p''$ on the $ox$ axis. By trigonometry, it is not a big deal to find the tangency points. (Check https://en.wikipedia.org/wiki/Tangent_lines_to_circles.)

Apply the rotation followed by the reverse translation to obtain the coordinates in the original system of axis.

• Thank you for this answer! Alas, it has the same issue as the one from Aretino (please read my reply there). – Thomas B. May 22 '17 at 17:25
• @ThomasB.: what is the benefit of having a single big, unreadable formula ?? – Yves Daoust May 22 '17 at 18:56

Maybe something you can use to derive an analytic solution:

We can use from elementary geometry : the radius always 90 degrees to the tangent. Therefore you can consider the Pythagorean theorem. Tangent points $t$ will be so that the vectors fulfill $$\|p-t\|_2^2 + r^2 = \|c-p\|_2^2$$

Where

• $r^2$ is radius and
• $p-t$ is the $x(rb\cos(\theta) -ra\sin(\theta) )$ I proposed in the comment
• $c-t$ is the $c+(rb\sin(\theta) + ra\cos(\theta))$ I proposed in the comment.