1

Consider the following MWE:

\documentclass{standalone}

\usepackage{tikz}

\makeatletter
\pgfdeclareshape{circtest}{ %
  \inheritsavedanchors[from={rectangle}] %
  \inheritbackgroundpath[from={rectangle}] %
  \inheritanchorborder[from={rectangle}] %
  \foreach \x in {center,north,north east,north west,south,south east,south west,east,west}{ %
    \inheritanchor[from={rectangle}]{\x} %
  } %
  \foregroundpath{ %
    \pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{center}} %
    \begin{pgfscope}[ %
        rotate=90, % nope
%         rotate around={90:(0,0)}, % nope
      ] %
      \foreach \angle [count=\xi] in {0,3,...,360} %
      {%
        \draw[ %
          rotate=90, % nope
          color=blue!\xi] (\angle:2cm) -- (\angle:3cm);
      }
    \end{pgfscope} %
  } % end \foregroundpath
} %


\begin{document}
\begin{tikzpicture}

  \node[circtest] (ctest) at (5,0) {};

  \begin{scope}[ %
      rotate=90, % ok
  %       rotate around={90:(0,0)}, % ok
    ] %
    \foreach \angle [count=\xi] in {0,3,...,360} %
    {%
      \draw[ %
  %         rotate=90, % ok
        color=black!\xi] (\angle:1cm) -- (\angle:2cm);
    }
  \end{scope}

\end{tikzpicture}
\end{document}

test01.png

The black ring is the one in {tikzpicture}/{scope}, and its coordinate system is rotated, as expected. However, using nearly the same syntax in \pgfdeclareshape ends up not rotating the coordinate system - which can be seen on the blue ring, which is a node of the custom circtest type.

Here basically, I want to specify (eventually) arguments with a dimension of angle, but I'd want my specification of 0 degrees to refer to "12 o'clock", and I'd want the coordinate system to be counterclockwise. I'm aware that in this case, I could just say \angle+90 inside the \pgfdeclareshape - but I'd rather use something like rotate=90 inside a scope for legibility reasons. Is there a way I could use such a syntax with a custom, \pgfdeclareshaped node?

1 Answer 1

1

Ok, I think I got it - instead of using {pgfscope}, just use \pgftransformrotate - and \pgftransformyscale{-1} to mirror; so the code becomes:

\documentclass{standalone}

\usepackage{tikz}

\makeatletter
\pgfdeclareshape{circtest}{ %
  \inheritsavedanchors[from={rectangle}] %
  \inheritbackgroundpath[from={rectangle}] %
  \inheritanchorborder[from={rectangle}] %
  \foreach \x in {center,north,north east,north west,south,south east,south west,east,west}{ %
    \inheritanchor[from={rectangle}]{\x} %
  } %
  \foregroundpath{ %
    \pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{center}} %
    \pgftransformrotate{90} %
    \pgftransformyscale{-1} %
    \foreach \angle [count=\xi] in {0,3,...,360} %
    {%
      \draw[ %
%           rotate=90, % nope
        color=blue!\xi] (\angle:2cm) -- (\angle:3cm);
    }
  } % end \foregroundpath
} %


\begin{document}
\begin{tikzpicture}

  \node[circtest] (ctest) at (5,0) {};

  \begin{scope}[ %
      rotate=90, % ok
  %       rotate around={90:(0,0)}, % ok
    ] %
    \foreach \angle [count=\xi] in {0,3,...,360} %
    {%
      \draw[ %
  %         rotate=90, % ok
        color=black!\xi] (\angle:1cm) -- (\angle:2cm);
    }
  \end{scope}

\end{tikzpicture}
\end{document}

... and the output becomes:

test01a.png

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.