2

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!

3 Answers 3

7

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

2
  • Thanks a lot. How can I draw a line from origin intersecting the circle at arbitrary point and ending on circle?
    – Immanuel
    Commented Mar 27, 2016 at 0:39
  • @Immanuel See updated answer. Commented Mar 27, 2016 at 0:55
3

It's not exactly tikz but here it's tkz-euclide. Tikz is my favorite tool to draw geometry's figures but I built tkz-euclide for math teachers to achieve results with a tool and a syntax similar to Latex. Euclide is based over tikz and you can use options and commands from tikz.

\documentclass[11pt]{scrartcl}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}

    \begin{tikzpicture}[scale=2]
        \tkzInit[xmin=0,xmax=3,ymin=-0.5,ymax=3]
             % axis defined by Init
        \tkzDrawX[noticks] \tkzDrawY[noticks]
             % it's fine to use points with names
             % rule if you use an object, you use parenthesis
             %      if you want to get an object, you use  curly braces
        \tkzDefPoints{0/2/A,0/0/O}
        \tkzDrawCircle[R](A,1.5 cm) % option R I use a radius
                                    % with \tkzDefPoint(1.5,2){C} 
                                    % \tkzDrawCircle(A,C)
        \tkzTangent[from with R=O](A,1.5 cm)  \tkzGetPoints{a}{b}
              % or \tkzTangent[from O](A,C)
        \tkzDrawSegments[color=green!50!black](O,a O,b A,a)
        \tkzMarkRightAngle(A,a,O)
              %  possible get a random point on the circle
              %  \tkzGetRandPointOn[circle=center A radius 1.5cm]{M}
              %  \tkzDrawSegment[color=red](O,M)
        \tkzDefPoint(1,4){B}
        \tkzInterLC[R](O,B)(A,1.5cm) \tkzGetPoints{x}{y}
              % or \tkzInterLC(O,B)(A,C)
        \tkzDrawSegment[color=red](O,x)
    \end{tikzpicture}   
\end{document}

enter image description here

2
  • Thanks for tkz-euclid. If possible, please consider providing English documentation.
    – Dilawar
    Commented Nov 14, 2019 at 10:16
  • @Dilawar I’ m not certain to write a full doc but a little one yes ! Commented Dec 2, 2019 at 19:06
0

I think tkz-euclide is a great tool, however it is still unstable which is problematic if you write some code and then reuse it a few years later. The answer has to be modulated depending which version you are using:

  • for version 1.16 (answer given): \tkzTangent[from ...]
  • for version 3.06: \tkzDefTangent[from = ...]
  • for version 4.2: \tkzDefLine[tangent from = ...]

The problem is to know exactly which version you are using if you use a Latex package linked either to Overleaf or a Linux distribution (in my case Mint).

  • My Latex package is updated by the distribution, it is very convenient but it is not always the latest version. Moreover Mint is Debian based, so installing and updating the TexLive.Iso is not easy, even discouraged.

  • You may get a wrong drawing without any diagnostic! Just check the following MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-fct}
\usepackage{tkz-euclide}
\usepackage[active,tightpage]{preview}
 \begin{document} 
\PreviewEnvironment{tikzpicture} .
\setlength\PreviewBorder{5pt}
\begin{tikzpicture}
\clip (-5,-4.5) rectangle (8.5,4);
\def \Xa{0}
\def \Ya{0}
\def \Xid{2*sqrt(3) + 2*sqrt(2)}
\def \Yid{2}
\def \rd{2}
\def \Xtab{2*sqrt(3) + 2*sqrt(2)}
\def \Ytab{0}
\def \Xtbc{2*sqrt(2) + 8*sqrt(3)/3}
\def \Ytbc{2*sqrt(6)/3 + 2}
\def \Xap{-2*sqrt(3) - 2*sqrt(2)}
\def \Yap{-sqrt(6) - 2}
\coordinate (Ap) at ({\Xap},{\Yap});
\coordinate (A) at ({\Xa},{\Ya});
\coordinate (I) at ({ \Xid },{\Yid });
\coordinate (K) at ({ \Xtbc },{ \Ytbc });
\coordinate (M) at ({ \Xtab },{\Ytab });
\tkzDrawCircle[blue](I,K);
%%% from manual tkz-euclide tool for Euclidean Geometry V3.06c p94
\tkzDefTangent[from = Ap](I,M) \tkzGetPoints{R}{Q};
\tkzDrawSegment[green](Ap,R);
%%% from manual tkz-euclide Euclidean Geometry V4.2c p43
\tkzDefLine[tangent from = Ap](I,M) \tkzGetPoints{Rp}{Qp}
\tkzDrawSegment[red](Ap,Rp);
\end{tikzpicture}
\end{document}



You will get a perfect compilation and the following result, no warnings!
Tangent to a circle from a given point

In my case the version 3.06 gives a correct result, not the most up to date version 4.2...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .