2

In the following code, I have a diameter drawn in a circle. Along the diameter, I draw seven equally spaced nodes. The two nodes closest to the center, but not the center, are labeled B and C. I want to get a certain shaded pattern - shaded gray - within the circle.

Here is the procedure. First, fill the circle with a shade of gray. (I chose gray!30.) Second, use the fill=white option to get a white semicircle centered at B that is above the diameter and a white semicircle centered at C that is below the diameter. Third, draw two circles, filled-in with gray!30 of radius 1 centered at (-2,0) and (2,0).

Here is my code. I get an error - there is something wrong with the command that I use to fill.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}


\begin{document}

\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[fill=gray!30] (O) circle (3);
\draw[fill] (-3,0) circle (1.5pt);
\draw[fill] (-2,0) circle (1.5pt);
\draw[fill] (-1,0) circle (1.5pt);
\draw[fill] (0,0) circle (1.5pt);
\draw[fill] (1,0) circle (1.5pt);
\draw[fill] (2,0) circle (1.5pt);
\draw[fill] (3,0) circle (1.5pt);
\draw (-3,0) -- (3,0);

\node[anchor=east] (A) at (-3,0) {$A$};
\node[anchor=south west] at (-1,0) {$B$};
\node[anchor=north east] at  (1,0) {$C$};
\node [anchor=west] at (3,0) {$D$};

\draw[fill=white] (-1,0) circle (2);
\draw[fill=white] (1,0) circle (2);
\draw[fill=gray!30] (-2,0) circ (1);
\draw[fill=gray!30] (2,0) circ (1);
\end{tikzpicture}

\end{document}
  • You are tired! get some rest and replace those circ with circle. – user11232 May 13 '15 at 15:57
  • Is this what you want? – user11232 May 13 '15 at 16:04
  • @Harish Kumar That mistake is utterly ridiculous! Not tired. (It is just after noon in New York.) I wasn't wearing my glasses. – Adelyn May 13 '15 at 16:09
  • @Harish Kumar The pattern is nearly what I want. I will use path to draw the two small circles of radius 1 - I just want the shading inside these smaller circles. – Adelyn May 13 '15 at 16:11
  • @Harish Kumar Did you notice how I spelled circle correctly in the last comment? – Adelyn May 13 '15 at 16:11
0
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}


\begin{document}

\begin{tikzpicture}

\coordinate (O) at (0,0);
\draw[fill=gray!30] (O) circle (3);
\draw[fill] (-3,0) circle (1.5pt);
\draw[fill] (-2,0) circle (1.5pt);
\draw[fill] (-1,0) circle (1.5pt);
\draw[fill] (0,0) circle (1.5pt);
\draw[fill] (1,0) circle (1.5pt);
\draw[fill] (2,0) circle (1.5pt);
\draw[fill] (3,0) circle (1.5pt);
\draw (-3,0) -- (3,0);

\node[anchor=east] (A) at (-3,0) {$A$};
\node[anchor=south west] at (-1,0) {$B$};
\node[anchor=north east] at  (1,0) {$C$};
\node [anchor=west] at (3,0) {$D$};

\path[fill=white] (-3,0) arc (180:0:2) -- (-3,0) -- cycle;
\path[fill=white] (3,0) arc (360:180:2) -- (3,0) -- cycle;
\path[fill=gray!30] (-2,0) circle (1);
\path[fill=gray!30] (2,0) circle (1);
\end{tikzpicture}

\end{document}

enter image description here

  • I want the gray region to be uniform. – Adelyn May 13 '15 at 16:26
  • All the shaded region. I guess I don't need inner shading and outer shading. – Adelyn May 13 '15 at 16:28
  • Also \draw[fill] can be \filldraw – user11232 May 13 '15 at 16:31
  • 1
    @Adelyn (-3,0) arc (180:0:2) means, start from (-3,0), draw an arc with starting angle 180 with a radius 2 units and end with an angle 0. Both 180 and 0 are measured from origin. You can also use (-3,0) arc [start angle=180,end angle=0,radius=2] See section 14.7 on page 153 of pgfmanual. – user11232 May 13 '15 at 16:39
  • 1
    \draw[fill=white] (-3,1) arc (180:0:2) -- (-3,1) -- cycle;. – user11232 May 13 '15 at 16:45

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.