[Tex/LaTex] Drawing a tangent from a point outside of a circle to it!

circlestikz-pgf

I have an easy question. I want to draw the tangents from origin to a circle with center at e.g. (0,2) and radius 1.5. Here the code of the circle:

\begin{tikzpicture}
\draw[->] (0,-.5) -- (3,-.5) node[right] {$x$}; 
\draw[->] (0,-.5) -- (0,2) node[above] {$y$};
\draw (0,2) circle (1.5);
\end{tikzpicture}

I need a simple solution, because I'm not good at drawing with tikz.
Thanks!

Best Answer

Tangent coordinate system

TikZ knows a tangent coordinate system for shapes, if library calc is loaded, see section "13.2.4 Tangent Coordinate Systems" of the PGF/TikZ manual.

The circle is drawn as node with circular shape:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,-.5) -- (3,-.5) node[right] {$x$};
\draw[->] (0,-.5) -- (0,2) node[above] {$y$};
% \draw (0,2) circle (1.5);
\node[circle, draw] (c) at (0, 2) [minimum size=3cm] {};
\draw[red]
  (0, 0) coordinate (a)
  -- (tangent cs:node=c, point={(a)}, solution=1)
  (0, 0)
  -- (tangent cs:node=c, point={(a)}, solution=2)
;
\end{tikzpicture}
\end{document}

Result

Trigonometry

The angle and length of the lines can be calculated using the law of sines and the Pythagorean theorem:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,-.5) -- (3,-.5) node[right] {$x$};
\draw[->] (0,-.5) -- (0,2) node[above] {$y$};
\draw (0,2) circle (1.5);
\pgfmathsetmacro\angle{asin(1.5/2)}
\pgfmathsetmacro\len{sqrt(2*2 - 1.5*1.5)}
\draw[red]
  (0, 0) -- (90 - \angle:\len)
  (0, 0) -- (90 + \angle:\len)
;
\end{tikzpicture}
\end{document}

Intersections

The question from the comment can be solved with library intersections. A line is defined, which goes through the circle. Then the intersections are calculated and the line drawn:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,-.5) -- (3,-.5) node[right] {$x$};
\draw[->] (0,-.5) -- (0,2) node[above] {$y$};
\draw[name path=circle] (0,2) coordinate (center) circle (1.5);
\coordinate (arbitrary point) at ($(center) + (-80:1.5)$);
% PGF/TikZ manual: 13.5.4 The Syntax of Distance Modifiers
\path[name path=line] (0, 0) -- ($(arbitrary point)!3cm!180:(0, 0)$);
\draw[red, name intersections={of=circle and line}]
  (0, 0) -- (intersection-1);
\end{tikzpicture}
\end{document}

Result