I'm trying to create several anchors equally spaced on the edge of my shape. The way I've tried to do this is to pass a key value in the node that would then define the anchors.
The following code is trying to achieve that by using a loop in the main pgfdeclareshape part. Although the loop works and creates an anchor ( in the wrong position for now ) it will only create one as the key still has the initial value.
\documentclass[a4paper]{article}
\usepackage{tikz}
\makeatletter
\tikzset{anchorpoints/.initial = 1}
\pgfdeclareshape{hat}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
% This loop will go through once for each anchorpoints and create an anchor
\c@pgf@counta=0
\pgfkeysgetvalue{/tikz/anchorpoints}{\anchorpoints}
\c@pgf@countb\anchorpoints\relax
\pgfmathloop
\ifnum\c@pgf@counta<\c@pgf@countb\relax
\pgfmathtruncatemacro{\anchorname}{\c@pgf@counta}\relax
\xdef\doanchor{
\noexpand\anchor{o\anchorname}{
\noexpand\northeast
\noexpand\pgf@y=1\noexpand\pgf@y%
}
}\doanchor
\advance\c@pgf@counta 1\relax
\repeatpgfmathloop
\backgroundpath{
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength{\pgf@xc}{\pgf@xa + (\pgf@xb - \pgf@xa)/2}
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathclose
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [shape=hat,draw=black,scale=0.75,anchorpoints=3] (1) at (0, 0) {};
\end{tikzpicture}
\end{document}
Is there any way to wait with creating the anchor until after the key has been set? If I try to put some .code to the key then it will execute at change but it seems that at that point it is too late to create the anchors.
shapes.geometriclibrary. Also you are inheriting the anchors of a rectangle for a triangle. Lastly,(anynodename.numberindegrees)is much easier to define the anchors. Otherwise you have to calculate the point on the border manually too. – percusse Jan 11 '13 at 18:29regular polygonshape. I think the code for that will be more illuminating than my TQFT code. – Andrew Stacey Jan 11 '13 at 23:04\expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@hat\endcsname{...}was precisely what I was looking for. The code both in your TQFT package and for the regular polygon was very helpful. I suppose posting that as some answer so I can mark the question as answered is the custom here? – Johan Paulsson Jan 12 '13 at 17:27