How to properly draw a circle with two tangent line marking the right angles

I've been trying to draw a figure, like the following draft, with precision for the last two days.

After a research on internet I was able to test a lot of softwares and script languages. Two script languages were promising.

1. PSTricks
2. tkz-Euclide

Using PSTricks I was able to draw the circle, the center of the circle and the tangent lines. The problem is that I couldn't find a way to represent the right angle. And I couldn't do that because the psCircleTangents script does not return two points, it returns a label to a point and I wasn't able to use this label to build the right angle marker, for instance, using the psframe.

\documentclass[11pt,a4paper,twoside]{article}

\begin{document}

\begin{pspicture}(0,3)(10,10)

\pscircle(8,0){2} %circle
\psdot(8,0)   % circle center
\psdot(0,-3) % a random point
\psCircleTangents(0,-3)(8,0){2} % script that calculates two tangent points
\pcline[nodesep=0,linecolor=blue](0,-3)(CircleT1) % drawing the tangent line to the first calculated tangent
\pcline[nodesep=0,linecolor=blue](0,-3)(CircleT2) % same for the second tangent

\end{pspicture}
\end{document}


My second attempt was to use the tkz-Euclide package. I wasn't able to fully understand the dynamic of the package since the documentation is only in french. I was able to mimic the same picture as produced for the first script but without understanding much.

\documentclass[11pt,a4paper,twoside]{article}

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}

\begin{tikzpicture}

\tkzInit
\tkzDefPoint(0,0){O}
\tkzDefPoint(6,6){E}
\tkzDefPoint(2,2){A}

\tkzDrawCircle(O,A)

\tkzTangent[from=E](O,A) \tkzGetPoints{e}{f}
\tkzGetPoints{k}{l}

\tkzDrawLines[](E,e E,l)

\end{tikzpicture}

\end{document}


It seems that the first PSTricks is more elegant but I'm not able to split the points I need to use.

Question 1: Is it possible to do so?

Question 2: Does anyone know how to take a tangent at tkz-Euclide and how to properly draw a right angle?

Question 3: Are there any other options I can use to draw this figure? I've already tried the following:

• Geogebra
• LaTeXDraw
• Eukleides

Thank you very much,

see "tikz & pgf manual", top of page 137:

code extracted from manual:

\begin{tikzpicture}
\draw[help lines] (0,0) grid (3,2);
\coordinate (a) at (3,2);
\node [circle,draw] (c) at (1,1) [minimum size=40pt] {$c$};
\draw[red] (a) -- (tangent cs:node=c,point={(a)},solution=1) --
(c.center) -- (tangent cs:node=c,point={(a)},solution=2) -- cycle;
\end{tikzpicture}


You're almost there. Just a slight modification of your code will get you there:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(12,0){E}
\tkzDefPoint(2,2){A}
\tkzDrawCircle(O,A)
\tkzLabelPoint(O){$O$}

\tkzTangent[from=E](O,A) \tkzGetPoints{e}{f}
\tkzDrawSegments(O,e O,f O,E)
\tkzMarkSegment[size=5pt,pos=.5,mark=|](e,E)
\tkzMarkSegment[size=5pt,pos=.5,mark=|](f,E)
\tkzMarkSegment[size=5pt,pos=.5,mark=||](O,E)
\tkzGetPoints{k}{l}

\tkzDrawSegments[](E,e E,l)
\tkzMarkRightAngle(O,e,E)
\tkzMarkRightAngle(O,f,E)
\end{tikzpicture}
\end{document}


The output running in Gummi gives:

Some comments. Using \usetkzobj allows it to recognize circles and other objects. It doesn't hurt to have it in every tkz-euclide diagram. First you defined points O (the center), a point E (used to construct the tangent), and point A (a point to be on the circle). \tkzDrawCircle draws the circle centered at O going through the point A. I then labeled the point O. The \tkzTangent macro computes the tangent from point E to the circle with center O containing A. There are two possible points of tangency which are calculated and put into variables e and f. Next, you want to draw segments, rather than lines, for the segment to begin and stop where you asked. Drawing a line adds a little more to the segment on each end. The segments are drawn and the markings are created using \tkzMarkSegment. The size determines how big the marking is, the 0.5 indicates it is halfway between and mark=| sets the mark to be used. The documentation, on page 77, indicates mark=||| is valid. The \tkzMarkRightAngle creates the right angle mark where the middle point is the vertex of the right angle.

I'm not familiar with pstricks. Initially I had looked into it years ago but found tkz-euclide to be much easier to use. Google translate can help you figure out the basics. There are also internet sites which have information, such as this page. Note the site has pages for circles and triangles as well.

I don't know French either.

\documentclass[11pt,a4paper,twoside]{article}

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}

\tkzInit
\tkzDefPoint(0,0){O}
\tkzDefPoint(6,0){E}
\tkzDefPoint(2,2){A}

\tkzDrawCircle(O,A)

\tkzTangent[from=E](O,A) \tkzGetPoints{e}{f}

%\tkzDrawLines[](E,e E,l)
\draw[-,postaction={decorate},decoration = {markings,mark=at position 0.5 with
{\draw[-] (0pt,-3pt)--(0pt,3pt);}}](E)--(e);
\draw[-,postaction={decorate},decoration = {markings,mark=at position 0.5 with
{\draw[-] (0pt,-3pt)--(0pt,3pt);}}](E)--(f);

\tkzInterLC(E,O)(O,A) \tkzGetPoints{k}{l}
\draw[-,postaction={decorate},decoration = {markings,mark=at position 0.6 with
{\draw[-] (-2pt,-3pt)--(-2pt,3pt);
\draw[-] (0pt,-3pt)--(0pt,3pt);
\draw[-] (2pt,-3pt)--(2pt,3pt);}}](E)--(k);

\end{tikzpicture}

\end{document}


UPDATE: I also noticed that the single and double marks, but not the triple marks, are built in tkz-euclide.

\documentclass[11pt,a4paper,twoside]{article}

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}

\tkzInit
\tkzDefPoint(0,0){O}
\tkzDefPoint(6,0){E}
\tkzDefPoint(2,2){A}

\tkzDrawCircle(O,A)

\tkzTangent[from=E](O,A) \tkzGetPoints{e}{f}

%\tkzDrawLines[](E,e E,l)
\draw[-](E)--(e);
\draw[-](E)--(f);

\tkzMarkSegments[mark=s|,mark size=6pt](E,e E,f)
\draw[-] (f) -- (O) -- (e);

\tkzInterLC(E,O)(O,A) \tkzGetPoints{k}{l}
\draw[-,postaction={decorate},decoration = {markings,mark=at position 0.6 with
{\draw[-] (-4pt,-3pt)--(-2pt,3pt);
\draw[-] (-1pt,-3pt)--(1pt,3pt);
\draw[-] (2pt,-3pt)--(4pt,3pt);}}](E)--(k);
% \tkzDrawSegment(E,k)
% \tkzMarkSegments[mark=s|||,mark size=6pt](E,k) %<- does not seem to work

\end{tikzpicture}

\end{document}


Here is a shortcode with pst-eucl, to display the construction of the tangents from a point to a circle, with the right angles marked:

\documentclass[11pt, a4paper, twoside, svgnames]{standalone}
\usepackage{pst-eucl} % for plane geometry
\usepackage{auto-pst-pdf} % to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TX Live, MacTeX))

\begin{document}

\begin{pspicture}(15,10)
\psset{PointSymbol=none, dotsize = 2.5pt, linejoin = 1, dimen = outer}
\pstGeonode[PosAngle = {0,90}](8, 0){O}(0,-3){M}
\pstCircleOA[Radius=\pstDistVal{2}, linecolor = IndianRed, linewidth = 1.2pt]{O}{}
\pstMiddleAB[ PointName=none]{O}{M}{I}
\psset{linewidth=0.6pt,}
CodeFigB=true, CodeFigColor=Gold, PosAngleA = -45, PosAngleB=90]{O}{}{I}{}{A}{B}
\psset{linecolor=Tomato, linewidth=0.6pt, nodesep=-2}
\pstLineAB{M}{A}\pstLineAB{M}{B}
\psline(A)(O)(B)
\psset{linecolor = LightSalmon}
\pstRightAngle*{M}{A}{O}
\pstRightAngle{M}{B}{O}
\psdots[dotsize = 2.5pt, linecolor = black](O)(M)(A)(B)
\end{pspicture}

\end{document}


Perhaps your search did not turn up Metapost? Here is an attempt that tries to show how to draw tangents to circles from an arbitrary exterior point.

This is wrapped up in luamplib so you should compile it with lualatex or work out how to adapt it for plain MP or the GMP package + pdflatex.

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path C;
pair o, p, a, b;
numeric t;

o = origin;
C = fullcircle scaled 144 shifted o;

p = 300 right rotated 10;

a = C intersectionpoint fullcircle scaled abs (p-o) shifted 1/2[o,p];

draw unitsquare scaled 5 rotated angle (o-a) shifted a withcolor 1/2 white;
draw unitsquare scaled 5 rotated angle (p-b) shifted b withcolor 1/2 white;

draw C withcolor 2/3 red;
draw o -- a -- p -- b -- o -- p;

dotlabel.lrt("$p$", p);
dotlabel.llft("$0$", o);

vardef mark_segment(expr A,B,N) =
for i=1 upto N:
draw (down--up) scaled 2
rotated 5
shifted 5/4(i-1-N, 0)
rotated angle (A-B)
shifted 1/2[A,B];
endfor
enddef;

mark_segment(p,a,1);
mark_segment(p,b,1);
mark_segment(p,o,3);

endfig;
\end{mplibcode}
\end{document}


this code uses only tikz and the calc library. It is used to draw the perpendicular symbol and do calculations (inside {}) with the variables \r, \ang and \side, for the symbol.

\documentclass{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\xdef\ang{65}%the angle starting from horizontal line
\xdef\side{5pt}%the size of the right angle symbol
\coordinate (O) at (0,0)node[below right]{$O$};%define coordinate O and label using node
\draw (O) circle[radius=\r];%draw the circle with center at O
\draw (O)--([shift=(\ang:\r)]O) coordinate(B);%draw the superior line inside the circle
\draw (B)--({\r*sec(\ang)},0) coordinate(A) node[midway, rotate={\ang-90}]{$|$}; %draw the superior line outside the circle. The length os this line is a factor of the secant of the angle and add | mark
\draw (O)--([shift=(-\ang:\r)]O) coordinate(C); %draw the inferior line inside the circle
\draw (C)--({\r*sec(-\ang)},0) coordinate(D) node[midway, rotate={-\ang-90}]{$|$};%draw the inferior line outside the circle and add | mark. points D and A are the same
\draw ($(B)!\side!(O)$) -- ($($(B)!\side!(O)$)!\side!90:(O)$) -- ($(B)!\side!(A)$);%draw the symbol at the superior triangle
\draw ($(C)!\side!(A)$) -- ($($(C)!\side!(A)$)!\side!90:(A)$) -- ($(C)!\side!(O)$);%draw the symbol at the inferior triangle
\draw (O)--(D) node[midway]{$|||$};%draw the horizontal line and add the ||| mark
\end{tikzpicture}
\begin{document}


sec() is the secant function

Thank you all for the answers.

Since the problem is solved, I'd like to explore a little bit in order to learn it more.

PSTricks seemed to me the more logical way to write it, does someone think it's possible to solve the same problem using this script?

Thanks,