2

I am trying to declare a custom pgf shape. I have a problem that I cannot access the east, west, north, south anchors. This works:

\pgfdeclareshape{mixer}{%
  \inheritsavedanchors[from=circle]
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \backgroundpath{%
    \pgf@x=\radius
    \pgf@y=\radius
    \centerpoint \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgfpathcircle{\pgfpoint{\pgf@xa}{\pgf@ya}}{\radius}
  }
}

However, as soon as I try to use something like:

\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y

or

\north \pgf@xa=\pgf@x \pgf@ya=\pgf@y

I get undefined command. Why is that?

  • because circle shape doesn't have those saved anchors. They are just anchors that are calculated upon call. – percusse Dec 01 '16 at 18:49
  • @percusse is there a way to access them from within \pgfdeclareshape? – user110971 Dec 01 '16 at 22:15
  • No because they don't exist until they are called. You have to define them yourself if need be – percusse Dec 01 '16 at 23:06
  • @user110971 Suggestion: have you looked at TikZ pics? They are kinda like shapes, but much more simple. Declaring new shapes are (I'd say) not for the end-user, but pics are. You can set coordinates inside the pic which behave like node anchors... Maybe it's what you looking for: check this link. – Guilherme Zanotelli Dec 05 '16 at 15:21

1 Answers1

4

You still have a chance: the definition of those anchors are hidden in

\pgf@anchor@⟨shape name⟩@⟨anchor name⟩

So \north can be retrieved by

\pgf@anchor@mixer@north

Full code

\documentclass{article}
\usepackage{tikz}

\begin{document}
\makeatletter
\pgfdeclareshape{mixer}{%
  \inheritsavedanchors[from=circle]
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \backgroundpath{%
    \centerpoint
    \pgfpathcircle{\pgfpoint{\pgf@x}{\pgf@y}}{\radius}
    \pgfpathmoveto{\pgf@anchor@mixer@east}
    \pgfpathlineto{\pgf@anchor@mixer@north}
    \pgfpathmoveto{\pgf@anchor@mixer@south}
    \pgfpathlineto{\pgf@anchor@mixer@west}
    \pgfusepath{stroke}
  }
}

\tikz\node[mixer]{0123456789};

\end{document}

Symbol 1
  • 36,855
  • How can I reference north east? – Matthias Apr 26 '23 at 17:45
  • I don't think that's possible, at least not directly. But you see, you can (1) retrieve the north anchor, (2) remember the y-coordinate, (3) retrieve the east anchor, (4) remember the x-coordinate, and (5) use x and y-coordinates as that of northeast anchor. – Symbol 1 Apr 26 '23 at 23:27
  • My pgf skills are not enough :-D Can you elaborate it in more detail? – Matthias May 01 '23 at 17:49
  • For northeast: (0) \newdimen\matt@x \newdimen\matt@y this declares new variables. (1)(2) \pgf@anchor@mixer@north \matt@y\pgf@y this remembers y coordinate. (3)(4) \pgf@anchor@mixer@east \matt@x\pgf@x this remembers x coordinate. (5) \pgfpathliineto{\pgfpoint{\matt@x}{\matt@y}} this uses the x and y coordinates. – Symbol 1 May 02 '23 at 01:28