Drehen einer benutzerdefinierten Form unabhängig vom Text

Drehen einer benutzerdefinierten Form unabhängig vom Text

Ich habe eine benutzerdefinierte Form mithilfe von erstellt pdfdeclareshapeund verwende sie im folgenden Diagramm

Bildschirmfoto

Ich möchte den Rahmen unabhängig vom Text drehen, so dass er im Idealfall irgendwann so aussieht wie das Bild indiese Frage.

Nach dem Studium derpgfHandbuch undSo drehen Sie einen Knoten und Text unabhängig voneinander in Tikz(zum Beispiel) denke ich, dass ich versuchen sollte, zu verwenden shape border rotate, aber nicht alle Formen unterstützen dies standardmäßig.

Kann der Rand meiner benutzerdefinierten Form unabhängig vom Text gedreht werden? (Wenn meine benutzerdefinierte Form verbessert werden kann, geben Sie uns gerne Kritik.)

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

Antwort1

Sie können einen verwenden shape border rotate, der für einige Formen vorhanden ist (oder Ihren eigenen speziellen petal rotateSchlüssel definieren). Wenn Sie jedoch eine neue Form definieren, müssen Sie die ganze Arbeit selbst erledigen. Das Zeichnen des Formrahmens ist unkompliziert, aber Sie möchten/müssen die Anker möglicherweise manuell definieren, um den Wert in diesem Schlüssel widerzuspiegeln (was hier nicht gemacht wird):

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

Bildbeschreibung hier eingeben

Antwort2

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

Bildbeschreibung hier eingeben

verwandte Informationen