6

I've got almost no time for this image, so the code is just a mess and probably the best example for never-ever-do-it-this-way-code in TikZ, but it works:

Result image

\documentclass[12pt, border=0.5mm]{standalone}
\usepackage{graphicx}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}    
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}

\begin{document}

\begin{tikzpicture}[x=0.75mm, y=0.75mm]

    \clip[] (-95, -26) rectangle (30, 12);

    \def\k{7};          

    \begin{scope}[rotate={deg(0.5*pi) - atan(1/0.22) - deg(0.03*pi)}]   

        \draw[red, line cap=round, line width=0.2mm, domain=-5*pi:2*pi, variable=\t, samples=500] plot[fixed point arithmetic] ({\t r}:{\k*exp(0.22*\t)});

        \draw[line width=0.1mm, domain=-91:0, variable=\t] plot[fixed point arithmetic] (\t, {tan(deg(1.03*pi))*\t});

        \draw[line width=0.1mm] ({0.53*pi r}:{\k*exp(0.22*0.53*pi)}) -- ({1.53*pi r}:{\k*exp(0.22*1.53*pi)});
        \draw[line width=0.1mm] ({1.03*pi r}:{\k*exp(0.22*1.03*pi)}) -- ({0.03*pi r}:{\k*exp(0.22*0.03*pi)});

        \begin{scope}
            \clip[rotate={deg(0.53*pi) + atan(1/0.22)}] (20, 0) rectangle (65, 19.75);  
            \clip[rotate={deg(0.03*pi)}] (-20, 0) rectangle (-65, -20); 
            \draw[line width=0.1mm] ({-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22)}, 0) -- ({\k*exp(0.22*1.53*pi)*cos(deg(1.53*pi))-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22)}, {\k*exp(0.22*1.53*pi)*sin(deg(1.53*pi))});
            \draw[line width=0.1mm] ({(-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22))-(\k*exp(0.22*1.03*pi) - \k*exp(0.22*0.53*pi))/sin(atan(0.22)}, 0) -- 
                ({\k*exp(0.22*1.53*pi)*cos(deg(1.53*pi))-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22))-(\k*exp(0.22*1.03*pi) - \k*exp(0.22*0.53*pi))/sin(atan(0.22)}, {\k*exp(0.22*1.53*pi)*sin(deg(1.53*pi))});
            \draw[line width=0.1mm] ({((-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22))-(\k*exp(0.22*1.03*pi) - \k*exp(0.22*0.53*pi))/sin(atan(0.22))-(\k*exp(0.22*0.53*pi) - \k*exp(0.22*0.03*pi))/sin(atan(0.22)}, 0) -- ({\k*exp(0.22*1.53*pi)*cos(deg(1.53*pi))-(\k*exp(0.22*1.53*pi) - \k*exp(0.22*1.03*pi))/sin(atan(0.22))-(\k*exp(0.22*1.03*pi) - \k*exp(0.22*0.53*pi))/sin(atan(0.22))-(\k*exp(0.22*0.53*pi) - \k*exp(0.22*0.03*pi))/sin(atan(0.22)}, {\k*exp(0.22*1.53*pi)*sin(deg(1.53*pi))});
        \end{scope}

        \draw[line width=0.2mm, domain=-95:25, variable=\t] plot[fixed point arithmetic] (\t, {tan(deg(0.53*pi)+atan(1/0.22))*\t + \k*exp(0.22*1.53*pi)*sin(deg(1.53*pi)) - tan(deg(0.53*pi)+atan(1/0.22))*\k*exp(0.22*1.53*pi)*cos(deg(1.53*pi))});

        \draw[line width=0.1mm, domain={deg(0.53*pi)}:{deg(0.53*pi)+atan(1/0.22)}, samples=100] plot({\k*exp(0.22*1.53*pi)*cos(deg(1.53*pi)) + 5*cos(\x)}, {\k*exp(0.22*1.53*pi)*sin(deg(1.53*pi)) + 5*sin(\x)});
                \node[font=\tiny] at (-0.35, -18) {$\gamma_0$};

        \node[font=\scriptsize] at (4, -10) {$R$};
        \node[font=\scriptsize] at (2, -23) {$P$};                              
        \node[font=\scriptsize] at (-52, -17) {$s(R)$};                             

        \fill[] (0, 0) circle (0.2mm);  

    \end{scope}
\end{tikzpicture}

\end{document}

I was redrawing this (handdrawn!) picture:

enter image description here

My question is, how to do it right? The code works, but it's nothing to be proud of. I will fix it in future, so this post is mostly a reminder for myself.

  • 3
    What are you trying to achieve? Do you have a question? – Matsmath May 24 '16 at 12:23
6

Obviously, this could be further simplified:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic,angles,quotes}
\begin{document}
\begin{tikzpicture}[x=0.75mm, y=0.75mm, font=\scriptsize, line width=.1mm]
  \def\k{7}
  \pgfmathsetmacro\m{\k*exp(0.22*1.53*pi)}
  \pgfmathsetmacro\n{\k*exp(0.22*0.03*pi)}
  \pgfmathsetmacro\p{\k*exp(0.22*0.53*pi)}
  \pgfmathsetmacro\q{\k*exp(0.22*1.03*pi)}
  \begin{scope}[rotate={deg(0.5*pi) - atan(1/0.22) - deg(0.03*pi)}]
    \draw [red, line cap=round, line width=0.2mm, domain=-5*pi:2*pi, variable=\t, samples=500] coordinate (o) plot [fixed point arithmetic] ({\t r}:{\k*exp(0.22*\t)}) coordinate (a);
    \draw [domain=-91:0, variable=\t] plot[fixed point arithmetic] (\t, {tan(deg(1.03*pi))*\t});
    \draw  ({0.53*pi r}:{\p}) coordinate (b) -- ({1.53*pi r}:{\m}) coordinate (p) node [below] {$P$} node [pos=.65, right] {$R$};
    \draw  ({1.03*pi r}:{\q}) -- ({0.03*pi r}:{\n});
    \begin{scope}
      \clip[rotate={deg(0.53*pi) + atan(1/0.22)}] (20, 0) rectangle (65, 19.75);
      \clip[rotate={deg(0.03*pi)}] (-20, 0) rectangle (-65, -20);
      \draw  ({(\q - \m)/sin(atan(0.22)}, 0) -- ({\m*cos(deg(1.53*pi))-(\m - \q)/sin(atan(0.22)}, {\m*sin(deg(1.53*pi))});
      \draw  ({(\p - \m)/sin(atan(0.22))}, 0) --
      ({\m*cos(deg(1.53*pi))+(\p - \m)/sin(atan(0.22))}, {\m*sin(deg(1.53*pi))});
      \draw  ({(\n - \m)/sin(atan(0.22))}, 0) -- ({\m*cos(deg(1.53*pi))+(\n - \m)/sin(atan(0.22))}, {\m*sin(deg(1.53*pi))});
    \end{scope}
    \node at (-52, -17) {$s(R)$};
    \fill (0, 0) circle (0.2mm);
  \end{scope}
  \draw [line width=0.2mm] (a |- p) -- ++(-120,0) coordinate (b);
  \pic [draw, font=\tiny, "$\gamma_0$"] {angle=o--p--b};
\end{tikzpicture}
\end{document}

somewhat simpler code

3

So, here is the code with no rotation and clipping tricks:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}

\begin{document}
\begin{tikzpicture}[x=1mm, y=1mm]

\def\k{7} 
\def\a{0.22}

\pgfmathsetmacro\tAngle{atan(1/\a)}
\pgfmathsetmacro\tAngleRad{2*pi(\tAngle/360)}

\pgfmathsetmacro\rOne{\k*exp(\a*(\tAngleRad))}
\pgfmathsetmacro\rTwo{\k*exp(\a*(\tAngleRad+0.5*pi))}
\pgfmathsetmacro\rThree{\k*exp(\a*(\tAngleRad+pi))}
\pgfmathsetmacro\rFour{\k*exp(\a*(\tAngleRad+1.5*pi))}

\pgfmathsetmacro\lOne{(\rFour-\rThree)/sin(atan(\a))}
\pgfmathsetmacro\lTwo{(\rThree-\rTwo)/sin(atan(\a))+\lOne}
\pgfmathsetmacro\lThree{(\rTwo-\rOne)/sin(atan(\a))+\lTwo}

\pgfmathsetmacro\startAngle{-4*pi}
\pgfmathsetmacro\endAngle{2*pi}  

\foreach \step in {0, 0.5*pi, 1.5*pi} {
    \draw[line width=0.05mm] (0, 0) -- 
    ({\k*exp(\a*(\tAngleRad+\step))*cos(deg(\tAngleRad+\step))}, {\k*exp(\a*(\tAngleRad+\step))*sin(deg(\tAngleRad+\step))}); 
}

\pgfmathsetmacro\an{2*pi*(360-\tAngle)/360} 

\pgfmathsetmacro\Sx{(\k*exp(\a*\an)*sin(deg(\an)))/(tan(90-\tAngle) - tan(\tAngle+deg(\an)))}
\pgfmathsetmacro\Sy{\k*exp(\a*\an)*sin(deg(\an)) + tan(\tAngle+deg(\an))}

\draw [line cap=round, line width=0.1mm, domain=\Sx:0, variable=\x] plot [fixed point arithmetic] ({\x}, {tan(90-\tAngle)*\x}); 

\draw [line cap=round, line width=0.1mm, domain=-100:14, variable=\x] plot [fixed point arithmetic]
        ({\k*exp(\a*\an)*cos(\an r) + \x}, {\k*exp(\a*\an)*sin(\an r) + tan(\tAngle+(\an r))*\x});

\draw [line cap=round, line width=0.2mm, domain=\startAngle:\endAngle, variable=\angle, samples=5000] 
    plot [fixed point arithmetic] ({\k*exp(\a*\angle)*cos(\angle r)}, {\k*exp(\a*\angle)*sin(\angle r)});

\fill[] (\Sx, \Sy) circle (0.25mm);

\pgfmathsetmacro\Px{\k*exp(\a*(\tAngleRad+1.5*pi))*cos(deg(\tAngleRad+1.5*pi))}
\pgfmathsetmacro\Py{\k*exp(\a*(\tAngleRad+1.5*pi))*sin(deg(\tAngleRad+1.5*pi))}

\draw [line cap=butt, 
        line width=0.05mm,
        domain=180:{180-\tAngle}, 
        variable=\angle, 
        samples=100] plot [fixed point arithmetic]
    ({\Px + 6*cos(\angle)}, {\Py + 6*sin(\angle)}); 

\fill[] (\Px, \Py) circle (0.25mm);

\fill[] (\Px-\lOne, \Py) circle (0.25mm);
\fill[] (\Px-\lTwo, \Py) circle (0.25mm);
\fill[] (\Px-\lThree, \Py) circle (0.25mm);

\pgfmathsetmacro\xOne{(\Py - tan(-\tAngle)*(\Px-\lOne))/(tan(90-\tAngle) - tan(-\tAngle))}
\pgfmathsetmacro\xTwo{(\Py - tan(-\tAngle)*(\Px-\lTwo))/(tan(90-\tAngle) - tan(-\tAngle))}
\pgfmathsetmacro\xThree{(\Py - tan(-\tAngle)*(\Px-\lThree))/(tan(90-\tAngle) - tan(-\tAngle))}      

\draw [line cap=round, line width=0.1mm, domain=\xOne:{\Px-\lOne}, variable=\x] plot [fixed point arithmetic] 
    ({\x}, {tan(-\tAngle)*\x + \Py - tan(-\tAngle)*(\Px-\lOne)});           
\draw [line cap=round, line width=0.1mm, domain=\xTwo:{\Px-\lTwo}, variable=\x] plot [fixed point arithmetic]
    ({\x}, {tan(-\tAngle)*\x + \Py - tan(-\tAngle)*(\Px-\lTwo)});   
\draw [line cap=round, line width=0.1mm, domain=\xThree:{\Px-\lThree}, variable=\x] plot [fixed point arithmetic] 
    ({\x}, {tan(-\tAngle)*\x + \Py - tan(-\tAngle)*(\Px-\lThree)});

\fill[] (\xOne, {tan(90-\tAngle)*\xOne}) circle (0.25mm);
\fill[] (\xTwo, {tan(90-\tAngle)*\xTwo}) circle (0.25mm);
\fill[] (\xThree, {tan(90-\tAngle)*\xThree}) circle (0.25mm);

\fill[] (0, 0) circle (0.25mm);

\node[font=\scriptsize] at ({\Px + 3.5*cos(180-0.5*\tAngle)}, {\Py + 3.5*sin(180-0.5*\tAngle)}) {$\gamma_0$};
\node[font=\scriptsize, anchor=north] at ({\Px}, {\Py}) {$P$};
\node[font=\scriptsize, anchor=north] at ({\Px}, {\Py+12}) {$R$};
\node[font=\scriptsize, anchor=north] at ({-50}, {\Py}) {$s(R)$};
\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.