Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create the image below

enter image description here

Here is my code

\documentclass[10pt,a4paper]{article}
\usepackage{tikz,tkz-euclide}

\begin{document}
\center
\begin{tikzpicture}
\tkzDefPoint(0,0){O}
\tkzDefPoint(0,1.25){A1}
\tkzDefPoint(0,3){A2}
\tkzDefPoint(3,0){A3}
\tkzDrawCircle[very thick,color=blue,fill=green!80!black,opacity=0.6](O,A2)
\tkzDrawCircle[fill=white](O,A1)
\end{tikzpicture}

\end{document}

My problem is, how Do I create the tangent line? And is there a more efficent way than mine? =)

share|improve this question
    
I guess the easiest is to use a circle node smallcircand refer to the smallcirc.north. You can either clip with the big circle or use the intersection library to get the points on the bigger circle. –  percusse Mar 5 '12 at 0:17
add comment

4 Answers

up vote 9 down vote accepted

If the tangent is horizontal, then no trig is needed and the following works.

\begin{tikzpicture}
\draw[thick,fill=green!20] (0,0) circle (2cm);
\path[clip] (0,0) circle (2cm);
\fill[green!30] (0,0) circle (2cm);
\draw[thick,blue,fill=white] (0,0) circle (1cm);
\draw[thick,red] (-2,1) -- (2,1) node[midway,above,black] {A};
\end{tikzpicture}

Note that this is pretty minimal, and just for generating the image you want. More sophisticated methods are available (see Jake's answer), but often I'll default to quick-and-dirty like this, because as much as I love making diagrams, time is money!

enter image description here

share|improve this answer
add comment

You can use \tkzDefPointWith[orthogonal](A1,O) to find a point on the tangent line passing through A1, and then use that new point together with \tkzInterLC to find the intersections between the tangent line and outer circle.

I would define the circles a bit differently:

\documentclass[border=5mm]{standalone}

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

\begin{document}

\begin{tikzpicture}
\tkzDefPoint(0,0){O} % centre
\tkzDefPoint(90:1){A} % defines small radius and tangent point
\tkzDefPoint(90:2){B} % defines large radius
\tkzDrawCircle(O,A)
\tkzDrawCircle(O,B)

\tkzDefPointWith[orthogonal](A,O) \tkzGetPoint{Q} % find a point Q orthogonal to AO
\tkzInterLC(A,Q)(O,B) \tkzGetPoints{A'}{A''} % find intersections of a line passing through A and Q with the large circle 
\tkzDrawSegment(A',A'') % draw the tangent
\tkzDrawPoints(A,A',A'') % show the points
\tkzLabelPoints[above](A)
\end{tikzpicture}
%
\end{document}

Of course, this can also be done with built-in TikZ mechanisms, namely the intersections library. Compared to a clipping approach, this has the advantage of making the end points of the tangent line available. By using the ($(<point>)!<factor>!<angle>:(<point>)$) syntax for defining the tangent, you can use arbitrary tangent points (like inner.37).

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc, intersections}

\begin{document}

\begin{tikzpicture}
\node (inner) [draw, circle, minimum size=2cm] {}; % draw the small circle
\node (outer) [draw, circle, minimum size=4cm, name path=outer] {}; % draw the large circle, name the path for finding the intersections later
\coordinate (O) at (0,0); % name the origin
\coordinate [label=A] (A) at (inner.90)  {}; % name the tangent point on the small circle

\begin{pgfinterruptboundingbox} % do not update the bounding box
\path [name path global=tangent] ($(A)!-10!90:(O)$) -- ($(A)!10!90:(O)$); % define the tangent path, make it long (20 times the radius of the small circle) to catch all intersections
\end{pgfinterruptboundingbox}

\draw [name intersections={of=outer and tangent}] (intersection-1) -- (intersection-2);
\filldraw [fill=gray] (intersection-1) circle [radius=1pt] (intersection-2) circle [radius=1pt];
\end{tikzpicture}
%
\end{document}
share|improve this answer
    
Another useful use of \begin{pgfinterruptboundingbox}. I'm going to rewrite tkz-euclide ! –  Alain Matthes Mar 5 '12 at 5:12
add comment

Just for fun with PSTricks.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}[showgrid=bottom](-3,-3)(3,3)
    \psclip{\pscustom[fillcolor=green,fillstyle=eofill]{\pscircle{3}\moveto(2,0)\pscircle{2}}}
        \psline[linecolor=red](-3,2)(3,2)
    \endpsclip
    \uput{2pt}[90](0,2){$A$}
\end{pspicture}
\end{document}

Animated version:

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\begin{document}
\multido{\n=0.0+0.1}{21}{%
\begin{pspicture}[showgrid=bottom](-3,-3)(3,3)
    \psclip{\pscustom[fillcolor=green,fillstyle=eofill]{\pscircle{3}\moveto(\n,0)\pscircle{\n}}}
        \psline[linecolor=red](-3,\n)(3,\n)
    \endpsclip
    \uput{2pt}[90](0,\n){$A$}
\end{pspicture}}
\end{document}
share|improve this answer
1  
no animation? :) just kidding :) –  cmhughes Sep 28 '12 at 17:23
1  
@cmhughes: Done. Thanks. –  I am who I say I am Sep 28 '12 at 17:31
    
no need for clipping here. Draw a simple green circle and then a white one. That's all. –  Herbert Sep 28 '12 at 18:57
    
@Herbert: But I want the hole to be transparent. –  I am who I say I am Sep 28 '12 at 18:58
1  
ok, I missed that point –  Herbert Sep 28 '12 at 19:17
add comment

only just for fun:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}\SpecialCoor
\begin{document}
\multido{\n=0.0+0.1,\iB=0+18}{21}{%
\begin{pspicture}[showgrid=bottom](-3,-3)(3,3)
  \psclip{\pscustom[fillcolor=green,fillstyle=eofill]{\pscircle{3}\moveto(\n,0)\pscircle{\n}}}
    \rput{\iB}(\n;\iB){%
       \psline[linecolor=red,linewidth=2pt](-5,\n)(3,\n)
       \psdot(-\n,\n)\uput{2pt}[90]{\iB}(-\n,\n){\Large A}}
    \endpsclip
\end{pspicture}}
\end{document}

enter image description here

share|improve this answer
    
\uput{2pt}[90]{-\iB}(-\n,\n){\Large A}. –  I am who I say I am Sep 28 '12 at 20:52
    
the rotation of A was intended, otherwise it is no fun :-) –  Herbert Sep 28 '12 at 20:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.