9

I am trying to fill a pattern in a section between two circles with TikZ.

image

In the code below, C0 is a circle with radius=1, center=(0,0). C1 is a circle through Point z0 with center=z1.

Calculating the coordinates of the two circles' intersections is too complicated task, so I want to specify the arcs between the two intersections' label.

But I found a difficulty in specifying an arc with the start/end points and the center.

Is there any straightforward solution to fill this kind of section?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,through,intersections}
\begin{document}
\begin{tikzpicture}
 % x, y axis
 \draw[->] (-1.5,0) -- (3,0) node[right] {$x$};
 \draw[->] (0,-1.5) -- (0,3) node[above] {$y$};
 % Origin
 \coordinate (O) at (0,0);

 % Point z0
 \coordinate (z0) at (1,0);
 \node [below right] at (z0) {$z_0$};
 % Circle C0
 \draw [name path=C0] (O) circle [radius=1];
 \node [above left] at (170:1) {$C_0$};
 % Point z1
 \coordinate (z1) at (30:0.7);
 \fill (z1) circle [radius=1pt];
 \node [below] at (z1) {$z_1$};

 % Circle C1
 \node [draw, circle through=(z0), name path=C1] at (z1) {};
 \node [above right] at ($(30:0.7)+(20:0.5)$) {$C_1$};

 % Intersections
 \path [name intersections={of=C0 and C1}];

\draw [pattern=north west lines, pattern color=gray!60!white] (z0)  arc (?:?:?) --(intersection-2) arc (?:?:1) --(z0);
\end{tikzpicture}
\end{document}
1
  • 2
    Welcome! Great first question: has code; is clear; has descriptive subject line :-).
    – cfr
    Commented Sep 8, 2016 at 10:53

4 Answers 4

7

Could you not just clip the filling pattern? (I say 'just' not because this is especially obvious, but because I find it much simpler than dealing with intersections!)

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{calc,patterns,through}
\begin{document}
\begin{tikzpicture}
 % x, y axis
 \draw[->] (-1.5,0) -- (3,0) node[right] {$x$};
 \draw[->] (0,-1.5) -- (0,3) node[above] {$y$};
 % Origin
 \coordinate (O) at (0,0);
 % Point z0
 \coordinate (z0) at (1,0);
 \node [below right] at (z0) {$z_0$};
 % Circle C0
 \draw  (O) circle [radius=1];
 \node [above left] at (170:1) {$C_0$};
 % Point z1
 \coordinate (z1) at (30:0.7);
 \fill (z1) circle [radius=1pt];
 \node [below] at (z1) {$z_1$};
 % Circle C1
 \node [draw, circle through=(z0)] at (z1) {};
 \node [above right] at ($(30:0.7)+(20:0.5)$) {$C_1$};
 \begin{scope}
   \clip (3,0) -- (z0) arc (0:90:1) -- (0,3) -| cycle;
   \node [pattern=north west lines, draw, pattern color=gray!60!white, circle through=(z0)] at (z1) {};
  \end{scope}
\end{tikzpicture}
\end{document}

clipped fill

6

Probably the easiest way is after filling C1 to re-filldraw C0, and finaly to draw the axes. Here is another solution using clipping, that use the "inverse clip" idea from an old Jake's answer and path picture clipping.

\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{calc,patterns,through,intersections}
\begin{document}
  \begin{tikzpicture}
    % x, y axis
    \draw[->] (-1.5,0) -- (3,0) node[right] {$x$};
    \draw[->] (0,-1.5) -- (0,3) node[above] {$y$};
    % Origin
    \coordinate (O) at (0,0);
    % Point z0
    \coordinate (z0) at (1,0);
    \node [below right] at (z0) {$z_0$};
    % Circle C0
    \draw [name path=C0] (O) circle [radius=1];
    \node [above left] at (170:1) {$C_0$};
    % Point z1
    \coordinate (z1) at (30:0.7);
    \fill (z1) circle [radius=1pt];
    \node [below] at (z1) {$z_1$};
    % Circle C1
    \node [draw, circle through=(z0), name path=C1,
      path picture={
        \clip (-20,-20) rectangle +(40,40) (O) circle [radius=1 cm +.5\pgflinewidth];
        \fill[pattern=crosshatch, pattern color=green] (-20,-20) rectangle +(40,40);
      }
    ] at (z1) {};
    \node [above right] at ($(30:0.7)+(20:0.5)$) {$C_1$};
  \end{tikzpicture}
\end{document}

enter image description here

6

I know this question has been dormant for a long time, but I thought of a novel solution using a couple of Metapost features. (Compile this with lualatex, or work out how to adapt it for GMP + pdflatex).

My idea was to try and capture the look of the hand-drawn green scribble in the OP.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{luatex85}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    numeric u; 
    u = 1cm;
    path C[], xx, yy;

    xx = (3 left -- 5 right) scaled u; yy = xx rotated 90;

    C0 = fullcircle scaled 4u;
    z0 = point 0 of C0;

    z1 = (1.2u, 0.7u);
    C1 = fullcircle scaled 2 abs(z1-z0) rotated angle (z0-z1) shifted z1;

    numeric n, s, t;
    (s, t) = C0 intersectiontimes C1;
    n = 16;

    draw point 0 of C0 for i=1 upto n: -- point s*i/n of C0 -- point t*i/n of C1 endfor 
         withpen pencircle scaled 1 
         withcolor 1/2 green;

    draw C0;
    draw C1;
    dotlabel.lrt("$z_0$", z0);
    dotlabel.bot("$z_1$", z1);
    drawarrow xx;
    drawarrow yy;

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

Note that to make the trick work, I had to rotate the smaller circle so that its point 0 coincides with the point 0 of the larger circle; this makes s and t give the times of the other intersection.

1

You can first fill the whole circle C1 with the pattern you want, then fill the whole C0 with the background color; i.e., write something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,through,intersections}
\begin{document}
\begin{tikzpicture}
 % Coordinates
 \coordinate (O) at (0,0);
 \coordinate (z0) at (1,0);
 \coordinate (z1) at (30:0.7);

 \node [fill, circle through=(z0), pattern=north west lines, pattern color=gray!60!white] at (z1) {};
 \fill [color=white] (O) circle [radius=1];

 % Point z0
 \node [below right] at (z0) {$z_0$};
 % Circle C0
 \draw [name path=C0] (O) circle [radius=1];
 \node [above left] at (170:1) {$C_0$};
 % Point z1
 \fill (z1) circle [radius=1pt];
 \node [below] at (z1) {$z_1$};

 % Circle C1
 \node [draw, circle through=(z0), name path=C1] at (z1) {};
 \node [above right] at ($(30:0.7)+(20:0.5)$) {$C_1$};

 % x, y axis
 \draw[->] (-1.5,0) -- (3,0) node[right] {$x$};
 \draw[->] (0,-1.5) -- (0,3) node[above] {$y$};
\end{tikzpicture}
\end{document}

Pay attention that the background filling commands must come before anything that describes labels, lines etc, otherwise the latter would be hidden by the background filling. Personally, I find it more convenient to define the axes in the end of the TikZ picture code block rather than at the start — precisely for the filling reasons.

1
  • 1
    Filling with the background is not the same as not drawing in the first place, and it simply isn't true that an order always exists that yields the same result. For example, consider drawing two of the crescent shapes requested by this question that cross in an 'X'.
    – Ben Voigt
    Commented Sep 8, 2016 at 14:58

You must log in to answer this question.