旋转(和镜像)在自定义节点 tikz 形状中绘制线条?

旋转(和镜像)在自定义节点 tikz 形状中绘制线条?

考虑以下 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}

测试01.png

{tikzpicture}黑色圆环是/中的圆环{scope},其坐标系按预期旋转。然而,在 中使用几乎相同的语法 \pgfdeclareshape最终会不是旋转坐标系——可以在蓝色环上看到,这是一个自定义circtest类型的节点。

基本上,我想在这里指定(最终)具有角度维度的参数,但我希望我的 0 度规范指的是“12 点钟”,并且我希望坐标系为逆时针。我知道在这种情况下,我只能说在 -\angle+90\pgfdeclareshape,但出于易读性原因,我宁愿使用rotate=90在范围内之类的东西。有没有办法将这种语法与自定义\pgfdeclareshaped 节点一起使用?

答案1

好的,我想我明白了——不是使用{pgfscope},而是使用\pgftransformrotate——和\pgftransformyscale{-1}镜像;所以代码变成:

\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}

...输出变成:

测试01a.png

相关内容