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?

2 Answers 2

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}
4
  • And how about format of fill, none black? Nov 8, 2014 at 1:21
  • @minthao_2011: Updated answer to include cross hatch pattern. Is this what the comment was about? Nov 8, 2014 at 1:24
  • 2
    Two circles and even odd rule avoids the white fill.
    – percusse
    Nov 8, 2014 at 1:35
  • Why 3 ellipses instead of 2 circles?
    – Sigur
    Nov 8, 2014 at 1:48
23

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

3
  • Beautiful brevity! Nov 8, 2014 at 2:25
  • 2
    Why all that typing? \tikz\draw[even odd rule, fill=gray!30] circle (3) circle (2); ;) Nov 8, 2014 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, 2014 at 14:33

You must log in to answer this question.

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