4

I want to fill a ring like this picture enter image description here

With Geogebra, I tried it by plot 4<=x^2+y^2<=9and this is the code in Geogebra

\documentclass[12pt]{standalone}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-3.3,-3.3) rectangle (3.3,3.3);
\draw [rotate around={0.:(0.,0.)},color=black] (0.,0.) ellipse (2.cm and 2.cm);
\draw [rotate around={0.:(0.,0.)},color=black,fill=black,fill opacity=0.1] (0.,0.) ellipse (3.cm and 3.cm);
\end{tikzpicture}
\end{document}

but, I got enter image description here

How can I fill the ring as the firt picture?

7

A simple way to do this kind of operation is fill the center circle with fill=white, and to get the cross hatch fill pattern you use pattern=crosshatch:

enter image description here

Code

\documentclass[12pt]{standalone}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-3.3,-3.3) rectangle (3.3,3.3);
\draw [rotate around={0.:(0.,0.)},color=black] (0.,0.) ellipse (2.cm and 2.cm);
\draw [rotate around={0.:(0.,0.)},color=black,fill=black,fill opacity=0.1] (0.,0.) ellipse (3.cm and 3.cm);
\draw [rotate around={0.:(0.,0.)},color=black,fill=white] (0.,0.) ellipse (2.cm and 2.cm);
\end{tikzpicture}
% -------------------
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-3.3,-3.3) rectangle (3.3,3.3);
\draw [rotate around={0.:(0.,0.)},color=black] (0.,0.) ellipse (2.cm and 2.cm);
\draw [rotate around={0.:(0.,0.)},color=black,fill=black,fill opacity=0.5, pattern=crosshatch] (0.,0.) ellipse (3.cm and 3.cm);
\draw [rotate around={0.:(0.,0.)},color=black,fill=white] (0.,0.) ellipse (2.cm and 2.cm);
\end{tikzpicture}
\end{document}
  • And how about format of fill, none black? – minthao_2011 Nov 8 '14 at 1:21
  • @minthao_2011: Updated answer to include cross hatch pattern. Is this what the comment was about? – Peter Grill Nov 8 '14 at 1:24
  • 2
    Two circles and even odd rule avoids the white fill. – percusse Nov 8 '14 at 1:35
  • Why 3 ellipses instead of 2 circles? – Sigur Nov 8 '14 at 1:48
21

Why all that typing?

\documentclass[border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!30,even odd rule]  (0,0) circle (3cm)
                                   (0,0) circle (2cm);
\end{tikzpicture}
% -------------------
\begin{tikzpicture}
\draw[even odd rule,pattern=crosshatch]  (0,0) circle (3cm)
                                         (0,0) circle (2cm);
\end{tikzpicture}
\end{document}

enter image description here

  • Beautiful brevity! – Przemysław Scherwentke Nov 8 '14 at 2:25
  • 1
    Why all that typing? \tikz\draw[even odd rule, fill=gray!30] circle (3) circle (2); ;) – Mark Wibrow Nov 8 '14 at 14:30
  • @MarkWibrow: Yes, but too much brevity may some times be difficult to understand. (certainly not in this case though) :-) – user11232 Nov 8 '14 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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