Tikz 正多边形角名称

Tikz 正多边形角名称

以下代码出现No shape named S.corner 1 is known.错误。我做错了什么?

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\begin{document}
    \begin{tikzpicture}
        \node[name=S,regular polygon, regular polygon sides=9, draw, minimum width=6cm] at (0,0) {};
        \pic [draw, angle radius=.6cm] {angle = S.corner 1--S.corner 6--S.corner 5};
    \end{tikzpicture}
\end{document}

答案1

tikzlibraryangles.code.tex包含

\def\tikz@lib@rightangle@background#1--#2--#3\pgf@stop{%
  \path [name prefix ..] [pic actions, draw=none] (#2.center)
    -- ++(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)
    -- ++(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)
    -- ++(\tikz@start@angle@temp:-\tikz@lib@angle@rad pt)
    -- cycle;
}%

从中您会看到它附加.center到第二个坐标。如果已经是锚点,则#2此方法不起作用。要解决此问题(而不是重新定义和附加的其他命令),您可以只定义辅助坐标。#2\tikz@lib@rightangle@background.center

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
    \node[name=S,regular polygon, 
    regular polygon sides=9, draw, minimum width=6cm] at (0,0) {};
    \path foreach \X in {1,...,9} {(S.corner \X) coordinate (corner \X)};
    \pic [draw, angle radius=.6cm] {angle = corner 1--corner 6--corner 5};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容