2

The following figure is meant to be a contour graph. How can I extend the current shading out to the rest of the figure, so that there is shading between all of the lines?

Here is the the figure and the code.

enter image description here

\documentclass[tikz]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}
  \newcounter{cntShader}
  \setcounter{cntShader}{60}
  \coordinate (o) at (0,0);
  \draw[->] (o) -- (+80:4) coordinate (b);
  \draw[->] (o) -- (-80:4) coordinate (c);
  \draw (o) -- (+170:3);
  \draw (o) -- (-170:3);
  \foreach \rad in {3,2.5,...,.5} {
    \draw pic[draw,fill=gray!\thecntShader, angle radius=\rad cm] {angle=c--o--b};
    \pgfmathsetcounter{cntShader}{\thecntShader-10}
    \setcounter{cntShader}{\thecntShader}
    \draw (+80:\rad cm) -- +(+170:3cm);
    \draw (-80:\rad cm) -- +(-170:3cm);
  }
\end{tikzpicture}
\end{document}
6

This does it (but is not the simplest way to obtain the result).

\documentclass[tikz]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}
  \newcounter{cntShader}
  \setcounter{cntShader}{60}
  \coordinate (o) at (0,0);
  \draw[->] (o) -- (+80:4) coordinate (b);
  \draw[->] (o) -- (-80:4) coordinate (c);
  \draw (o) -- (+170:3);
  \draw (o) -- (-170:3);
  \foreach \rad in {3,2.5,...,.5} {
    \draw pic[draw,fill=gray!\thecntShader, angle radius=\rad cm] {angle=c--o--b};
    \path (+80:\rad cm-0.5cm) +(+170:3cm) coordinate (auxp)
    (-80:\rad cm-0.5cm) +(-170:3cm) coordinate (auxm);
    \path[fill=gray!\thecntShader] (+80:\rad cm) -- +(+170:3cm) -- (auxp)
     -- (+80:\rad cm-0.5cm) -- cycle;
    \path[fill=gray!\thecntShader] (-80:\rad cm) -- +(-170:3cm) -- (auxm)
     -- (-80:\rad cm-0.5cm) -- cycle;
    \pgfmathsetcounter{cntShader}{\thecntShader-10}
    \setcounter{cntShader}{\thecntShader}
    \draw (+80:\rad cm) -- +(+170:3cm);
    \draw (-80:\rad cm) -- +(-170:3cm);
  }
\end{tikzpicture}
\end{document}

enter image description here

I personally would go along an arguably easier path:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[line join=bevel]
  \coordinate (o) at (0,0);
  \foreach \rad [count=\Z starting from 0] in {3,2.5,...,.5}  {
  \pgfmathtruncatemacro{\GL}{60-10*\Z}
  \draw[line width=5mm,gray!\GL] (+80:\rad cm-0.25cm) +(+170:3cm) -- (+80:\rad cm-0.25cm)
  arc(80:-80:\rad cm-0.25cm) -- ++ (-170:3cm);
  \draw (+80:\rad cm) +(+170:3cm) -- (+80:\rad cm)
  arc(80:-80:\rad cm) -- ++ (-170:3cm);}
  \draw (+170:3cm) -- (o) -- (-170:3cm);
  \draw[<->] (+80:4) coordinate (b) -- (o) -- (-80:4) coordinate (c);
\end{tikzpicture}
\end{document}

enter image description here

  • +1 More efficient as always:) – Andrew Jun 6 at 23:41
  • Thanks for the code! This looks great. It's easier to tell with the PDF: the vertex of the narrow cone (which opens to the left), protrudes just to the right of the origin, where it intersects with the lines that lean at 80 and -80 degrees. Is there a way of eliminating this? – Michael Jun 7 at 2:37
  • @Michael Yes, of course. Just replace \begin{tikzpicture} by \begin{tikzpicture}[line join=bevel]. – user121799 Jun 7 at 3:09
4

Something like this:

enter image description here

Here is the code:

\documentclass[tikz, border=20mm]{standalone}
\usetikzlibrary{angles,calc}
\begin{document}
\begin{tikzpicture}
  \newcounter{cntShader}
  \setcounter{cntShader}{60}
  \coordinate (o) at (0,0);
  \draw[->] (o) -- (+80:4) coordinate (b);
  \draw[->] (o) -- (-80:4) coordinate (c);
  \draw (o) -- (+170:3);
  \draw (o) -- (-170:3);
  \foreach \rad [evaluate=\rad as \prad using {\rad-0.5}, count=\c,
                 evaluate=\c as \sh using {70-10*\c}] in {3,2.5,...,.5} {
    \draw pic[draw,fill=gray!\sh, angle radius=\rad cm] {angle=c--o--b};
    \draw[fill=gray!\sh](+80:\prad cm)--(+80:\rad cm)--++(170:3cm)--($(+80:\prad cm)+(170:3cm)$)--cycle;
    \draw[fill=gray!\sh](-80:\prad cm)--(-80:\rad cm)--++(-170:3cm)--($(-80:\prad cm)+(-170:3cm)$)--cycle;
  }
\end{tikzpicture}
\end{document}

Note also that I have replaced your cntShader with \sh using count=\c, evaluate=\c as \sh using {70-10*\c} inthe \foreach statement.

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.