4

I borrowed some code from TikZ circuits: symbol for gas discharge tube? to define my own symbol. The inner arc should have an arrow at one end, what I do not manage to get. What's wrong with my code? Here's my attempt:

\documentclass{article}

\usepackage{tikz}

\begin{document}

\makeatletter
\pgfdeclareshape{circulator}
{
    \inheritsavedanchors[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{west}
    \inheritanchor[from=circle]{north east}
    \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{south east}
    \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{input}
    \inheritanchor[from=circle]{output}
    \inheritanchorborder[from=circle]

    \backgroundpath{
        \pgf@process{\radius}
        \pgfutil@tempdima=\radius

        \pgfpathcircle{\centerpoint}{\pgfutil@tempdima}

        \pgfsetarrowsstart{latex}
        \pgfpathmoveto{\pgfpoint{.7\pgfutil@tempdima}{0pt}}
        \pgfpatharc{0}{120}{.7\pgfutil@tempdima}
        \pgfusepath{stroke}

    }
}
\makeatother

\begin{tikzpicture}
  \node [circulator] at (0,0) {};
\end{tikzpicture}

\end{document}

enter image description here

Chris
  • 3,301
  • 2
  • 20
  • 23

1 Answers1

8

Here are two solutions. In both case, you have to stroke two paths: the circle (without arrow) then the arc (with an arrow).

1st solution

In this first solution, I added an extra line to avoid a bad position of the arrow head.

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\makeatletter
\pgfdeclareshape{circulator}
{
    \inheritsavedanchors[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{west}
    \inheritanchor[from=circle]{north east}
    \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{south east}
    \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{input}
    \inheritanchor[from=circle]{output}
    \inheritanchorborder[from=circle]

    \backgroundpath{
        \pgf@process{\radius}
        \pgfutil@tempdima=\radius

        \pgfpathcircle{\centerpoint}{\pgfutil@tempdima}
        \pgfusepath{stroke}

        \pgfsetarrowsstart{Latex[length=2pt]}
        \pgfpathmoveto{\pgfpoint{.7\pgfutil@tempdima}{-2pt}}
        \pgfpathlineto{\pgfpoint{.7\pgfutil@tempdima}{0pt}}
        \pgfpatharc{0}{120}{.7\pgfutil@tempdima}
        \pgfusepath{stroke}

    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
  \node [circulator] at (0,0) {};
\end{tikzpicture}
\end{document}

2d solution

Here is another solution without an extra line (using the bending TikZ library to adjust the position of the arrow head).

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,bending}

\makeatletter
\pgfdeclareshape{circulator}
{
    \inheritsavedanchors[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{north}
    \inheritanchor[from=circle]{south}
    \inheritanchor[from=circle]{east}
    \inheritanchor[from=circle]{west}
    \inheritanchor[from=circle]{north east}
    \inheritanchor[from=circle]{north west}
    \inheritanchor[from=circle]{south east}
    \inheritanchor[from=circle]{south west}
    \inheritanchor[from=circle]{input}
    \inheritanchor[from=circle]{output}
    \inheritanchorborder[from=circle]

    \backgroundpath{
        \pgf@process{\radius}
        \pgfutil@tempdima=\radius

        \pgfpathcircle{\centerpoint}{\pgfutil@tempdima}
        \pgfusepath{stroke}

        \pgfsetarrowsstart{Latex[length=2pt]}
        \pgfpathmoveto{\pgfpoint{.7\pgfutil@tempdima}{0pt}}
        \pgfpatharc{0}{120}{.7\pgfutil@tempdima}
        \pgfusepath{stroke}

    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
  \node [circulator] at (0,0) {};
\end{tikzpicture}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • Thanks, Paul, for the working solution. Can you explain why this extra line is needed? In my example there's no visible difference but I can imagine cases where the extra line is problematic. Is there a solution without it? – Chris Jun 03 '14 at 08:29
  • @Chris I edited my answer... – Paul Gaborit Jun 03 '14 at 15:23
  • Thanks again, @Paul Gaborit, I'll accept the answer, but I'm still interested in the reasons behind this behaviour of the arc to gain a better understanding of pgf. – Chris Jun 03 '14 at 15:39
  • @Chris See this answer... – Paul Gaborit Jun 03 '14 at 15:51