獨立於文字旋轉自訂形狀

獨立於文字旋轉自訂形狀

我使用 建立了一個自訂形狀pdfdeclareshape,並在下圖中使用它

螢幕截圖

我想獨立於文字旋轉邊框,以便理想情況下它最終看起來像中的圖像這個問題

經研究了pgf手冊和如何在 Tikz 中獨立旋轉節點和文本(例如),我認為我應該瞄準使用shape border rotate,但並非所有形狀預設都支援它。

我的自訂形狀的邊框可以獨立於其文字進行旋轉嗎? (如果我的自訂形狀可以改進,請隨時批評。)

% arara: pdflatex
\documentclass[tikz]{standalone}

\makeatletter
\pgfdeclareshape{petal}
{
    \inheritsavedanchors[from=circle] % this is nearly a circle
    \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{base}
    \backgroundpath{
        % origin
        \centerpoint%
        \pgf@xc=\pgf@x%
        \pgf@yc=\pgf@y%
        \pgfutil@tempdima=\radius%
        \pgfpathmoveto{\pgfpointadd%
            {\pgfqpoint{\pgf@xc}{\pgf@yc}}
            {\pgfqpoint{-\pgfutil@tempdima}{0\pgfutil@tempdima}}}
        \pgfpatharc{180}{0}{\pgfutil@tempdima}
        \pgfpathcurveto{%
            \pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0.9\pgfutil@tempdima}{-.9\pgfutil@tempdima}}}
            {\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0.5\pgfutil@tempdima}{-.5\pgfutil@tempdima}}}
            {\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}}
        \pgfpathcurveto{%
            \pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{0\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}}
            {\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-0.8\pgfutil@tempdima}{-.8\pgfutil@tempdima}}}
            {\pgfpointadd{\pgfqpoint{\pgf@xc}{\pgf@yc}}{\pgfqpoint{-\pgfutil@tempdima}{0\pgfutil@tempdima}}}
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
    \foreach \i in {1,2,...,5}
    {
        \pgfmathparse{90-(\i-1)*360/5}
        \node[draw=black,anchor=base,rotate=-(\i-1)*360/5,petal,minimum width=1.5cm] at (\pgfmathresult:1.2cm)  {\i};
    }
\end{tikzpicture}

\end{document}

答案1

您可以使用shape border rotate某些形狀存在的 a (或定義您自己的特殊petal rotate鍵)。然而,當您定義新形狀時,您必須自己完成所有工作。繪製形狀邊框很簡單,但您可能需要/必須手動定義錨點以反映此鍵中的值(此處未完成):

\documentclass[tikz]{standalone}

\makeatletter
\pgfkeys{/pgf/shape border rotate/.initial=0}

\pgfdeclareshape{petal}
{
    \inheritsavedanchors[from=circle] % this is nearly a circle
    \inheritanchorborder[from=circle]
    \inheritanchor[from=circle]{center}
    \inheritanchor[from=circle]{base}
    \savedmacro\petalparameters{%
      \pgfmathsetmacro\shapeborderrotate{\pgfkeysvalueof{/pgf/shape border rotate}}%
      \addtosavedmacro\shapeborderrotate%
    }
    \backgroundpath{
      % origin
      \petalparameters%
      {% Make sure transformations are  inside group.
         \pgftransformshift{\centerpoint}%
        \pgftransformrotate{\shapeborderrotate}%
        \pgfutil@tempdima=\radius%
        \pgfpathmoveto{\pgfqpoint{\pgfutil@tempdima}{0pt}}%
        \pgfpatharc{0}{180}{\pgfutil@tempdima}%
        \pgfpathcurveto{\pgfqpoint{-\pgfutil@tempdima}{-.5\pgfutil@tempdima}}%
          {\pgfqpoint{-.5\pgfutil@tempdima}{-.75\pgfutil@tempdima}}%
          {\pgfqpoint{0pt}{-1.5\pgfutil@tempdima}}
        \pgfpathcurveto{\pgfqpoint{0pt}{-.75\pgfutil@tempdima}}%
          {\pgfqpoint{\pgfutil@tempdima}{-.75\pgfutil@tempdima}}%
          {\pgfqpoint{\pgfutil@tempdima}{0pt}}%
      }%
   }
}
\makeatother

\begin{document}
\begin{tikzpicture}
    \foreach \i in {1,2,...,5}
    {
        \pgfmathparse{90-(\i-1)*360/5}
        \node[draw=black,anchor=base,shape border rotate=-(\i-1)*360/5,petal,minimum width=1.5cm] at (\pgfmathresult:1.25cm)  {\i};
    }
\end{tikzpicture}

\end{document}

在此輸入影像描述

答案2

使用 PSTricks。

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\psset{linejoin=1}
\SpecialCoor
\def\atom#1%
{
    \psccurve(0,0)(.3,.5)(1,1)(1,1.5)(0,2)(-1,1.5)(-1,1)
    \rput{*0}(0,1){#1}
}

\begin{document}
\begin{pspicture}[showgrid=false](-3,-3)(3,3)
    \multido{\ia=90+-72,\ib=0+-72,\in=1+1}{5}{\rput(.5;\ia){\rput{\ib}(0,0){\atom{\in}}}}
\end{pspicture}
\end{document}

在此輸入影像描述

相關內容