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.
Thanks in advance!
 A: 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.
A: 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||}.
$$
A: 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.

