9

I have a couple of problems while drawing a picture with TikZ. The picture I would like to obtain is like the following:

this one.

Here is my code:

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{positioning,patterns}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=2]
\clip(0,0) rectangle (6,6);
\draw[thick] (3.,3.) circle ({pi/2});
\pgfmathsetmacro{\x}{1};
\draw[thick,pattern=north west lines, pattern color=black] (3.,3.) circle ({rad(atan(\x))});
\begin{scope}[shift={(3,3)}]
\foreach \z in {0.5,1,2,3}
\draw [variable=\y,domain=-\z+0.001:\z-0.001] plot ({deg(\y)+90}:{rad(atan( (\x*(1-(cosh(\x*\y)/cosh(\x*\z))^2)^(-0.5)))});
\end{scope}
\end{tikzpicture}
\end{document}

What I obtain is

enter image description here

I have two problems:

  • I have infinities in my calculation. That gave all sort of problems, so I restricted the domain in the plot so that I don't include the singular point (which then is mapped to a finite value by the arctan function). However, in this way I cannot get to the proper value and the plots do not touch the outer circle.
  • The plot lines are not smooth.

Any ideas on how to solve this?

  • By default when you draw something TikZ use 25 points. You can change this by putting for example samples=300 in your \draw command. This will smooth the curve. – Kpym Dec 14 '14 at 11:41
  • You can solve your first problem by cheating : make your circle a little bit smaller (and clip with it). – Kpym Dec 14 '14 at 11:42
  • or if you want less accuracy but faster compile you can put less points (for example samples=100), but add smooth and play with tension. – Kpym Dec 14 '14 at 12:00
10

Takes a bit to compile but looks like it comes close. I used pgfplots to handle the plotting and infinity issues etc. It already provides a polaraxis environment so no need to do extra work. You can also invoke a gnuplot directive to get more precision. I would strongly recommend changing the colormap though. Even Matlab finally stopped using it in 2014b.

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns,pgfplots.polar}
\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[samples=200,grid=none,enlargelimits=false,
                  xtick=\empty,ytick=\empty,axis y line={none}]
 \pgfmathsetmacro{\x}{1};
 \pgfplotsinvokeforeach{0.15,0.3,...,3,pi}{
 \addplot[mesh,domain=-#1+1e-3:#1-1e-3,variable=\y,
          point meta=12-\plotnumofactualtype, % For color match
          point meta max=30] 
         ({deg(\y)+90},{rad(atan( (\x*(1-(cosh(\x*\y)/cosh(\x*#1))^2)^(-0.5)))});}
\end{polaraxis}
\end{tikzpicture}
\end{document}

enter image description here

  • the lines are not touching the boundary. A little bit smaller circle (with clip) will be ok. I have not investigated if this is a precision problem or something else, I'm just looking and admiring your picture ! – Kpym Dec 14 '14 at 15:46
  • 1
    @Kpym You can add ymax=1.4. Because it is an axis, it will limit the visible area. – percusse Dec 14 '14 at 17:49
7

This is a cheating lesson (you can see my comments), not a real solution.

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,patterns}

\begin{document}
  \begin{tikzpicture}[scale=2]
    \clip (3.,3.) circle ({pi/2 - .05});
    \pgfmathsetmacro{\x}{1};
    \draw[thick,pattern=north west lines, pattern color=black] (3.,3.) circle ({rad(atan(\x))});
    \begin{scope}[shift={(3,3)}]
      \foreach[evaluate=\z as \c using .3*\z] \z in {.1,.3,...,3,3.14} {
        \definecolor{currentcolor}{hsb}{\c,1,1}
        \draw [variable=\y,domain=-\z+0.001:\z-0.001, smooth, samples=100, currentcolor] 
        plot ({deg(\y)+90}:{rad(atan( (\x*(1-(cosh(\x*\y)/cosh(\x*\z))^2)^(-0.5)))});
      }
    \end{scope}
    \draw[very thick] (3.,3.) circle ({pi/2 - .059});
  \end{tikzpicture}
\end{document}

enter image description here

EDIT: And here is a real solution using atan2 to avoid infinity problems.

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
  \begin{tikzpicture}[scale=2]
    \draw[thick,pattern=north west lines, pattern color=black] circle (pi/4);
    \foreach[
      evaluate=\z as \c using \z/180,
      evaluate=\z as \chz using cosh(rad(\z))]
      \z in {10, 20, ..., 180} {
        \definecolor{currentcolor}{hsb}{\c,1,1}
        \draw [variable=\y,domain=-\z:\z, smooth, samples=100, currentcolor]
            plot({\y + 90} : {rad(atan2(\chz, sqrt((\chz)^2 - (cosh(rad(\y)))^2)))});
      }
    \draw[very thick] circle (pi/2);
  \end{tikzpicture}
\end{document}

enter image description here

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.