4

I want to draw the following picture, but I'm having trouble with the region between the two circles

I've been trying to use scope however I'm only able to fill the whole intersection.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw[->][thin,color=blue] (0,0) -- (-3,0) coordinate[label = {below:$y$}];
\draw[->][thin,color=blue]  (0,0) -- (0,3) coordinate[label = {right:$x$}];
\draw[->][thin,color=blue]  (0,0) -- (3,-3) coordinate[label = {left:$z$}];

\draw (0,0) circle (2cm);
\draw (0,0) circle (2.25cm);


\def\circleone{ (0,0) circle (2cm) }
\def\circletwo{ (0,0) circle (2.25cm) }


\begin{scope}

\clip \circletwo;

\fill[white, opacity=0.2] \circleone;

\end{scope}

\begin{scope}

\clip
\circleone
(current bounding box.south west) rectangle
(current bounding box.north east);
\fill[blue,opacity=0.2] \circletwo;

\end{scope}

\end{tikzpicture}
\end{document}
3
  • I don't quite understand, do you mean you have problems with that little red bit at the top of the circle? Jun 15, 2017 at 20:44
  • Yes, I don't want to fill the whole circle just that red section above. Jun 15, 2017 at 20:47
  • This may be a bug (or bad thinking on my part): The manual states that for self-intersecting paths, the even odd rule applies when it comes to clipping; That is, if you have an even number of clipping areas overlapping, it does not clip. Hence \clip (0,0) circle (2) circle (2.25); should work, but it doesn't. Work-around: \clip (0,0) circle (2.25); \clip (0,0) circle (2) (-4,-4) rectangle (4,4); followed by whatever you want to clip in your area. (Inside a scope)
    – Huang_d
    Jun 15, 2017 at 21:01

3 Answers 3

8

This is the easiest way. Slightly more complicated would be to make the sides vertical rather than angled. There was nothing to indicate how wide to make it.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw[->][thin,color=blue] (0,0) -- (-3,0) coordinate[label = {below:$y$}];
\draw[->][thin,color=blue]  (0,0) -- (0,3) coordinate[label = {right:$x$}];
\draw[->][thin,color=blue]  (0,0) -- (3,-3) coordinate[label = {left:$z$}];

\draw (0,0) circle (2cm);
\draw (0,0) circle (2.25cm);

\fill[blue,opacity=0.2] (85: 2cm) arc[radius=2cm, start angle=85, end angle=95]
  -- (95: 2.25cm) arc[radius=2.25cm, start angle=95, end angle=85] -- cycle;

\end{tikzpicture}
\end{document}

demo

5

Here is another suggestion using the even odd rule for the blue filling. The red part is added as path picture.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,intersections,backgrounds}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\draw[->][thin,color=blue] (O) -- +(-3,0) coordinate[label = {below:$y$}];
\draw[->][thin,color=blue] (O) -- +(0,3) coordinate[label = {right:$x$}];
\draw[->][thin,color=blue] (O) -- +(3,-3) coordinate[label = {left:$z$}];

\begin{scope}[on background layer]
\draw[even odd rule,fill=blue,fill opacity=.2]
  [path picture={\fill[red,opacity=1](O)+(-.2,0)rectangle+(.2,0|-current bounding box.north);}]
  (O)
  circle [radius=2]
  circle[radius=2.25]
;
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

To get the axis on top I have drawn them in a background layer. Instead you could draw the axis after the circles.

Additionally I have replaced all the (0,0) by the already defined (O) and then I have used coordinates relative to (O).

5

One more alternative:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,intersections}

\begin{document}
\begin{tikzpicture}[
 ax/.style = {->, thin,color=blue},
                    ]
\coordinate (O) at (0,0);
% circle
\draw[double=blue!30,double distance=2.5mm,thick]       
            (O) circle (21.25mm);
% arc segment
\filldraw[semithick,red!50]
            (85:2.01) arc[radius=2.01, start angle=85, end angle=95] --
            (95:2.24) arc[radius=2.24, start angle=95, end angle=85] -- cycle;
% axes
\draw[ax]   (O) -- (-3,0) node[below] {$y$};
\draw[ax]   (O) -- ( 0,3) node[left]  {$x$};
\draw[ax]   (O) -- (3,-3) node[right] {$z$};
%
\end{tikzpicture}
\end{document}

enter image description here

or slightly simpler:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,intersections}

\begin{document}
\begin{tikzpicture}[
 ax/.style = {->, thin,color=blue},
                    ]
\coordinate (O) at (0,0);
% circle
\draw[double=blue!30,double distance=2.5mm,thick]       
            (O) circle (21.25mm);
% arc segment
\draw[double=red!50,double distance=2.5mm,thick]
            (85:21.25mm) arc[radius=21.25mm, start angle=85, end angle=95];
% axes
\draw[ax]   (O) -- (-3,0) node[below] {$y$};
\draw[ax]   (O) -- ( 0,3) node[left]  {$x$};
\draw[ax]   (O) -- (3,-3) node[right] {$z$};
%
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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