Tikz 图片的旋转

Tikz 图片的旋转

我必须将这个图形逆时针旋转九十度,并用一些颜色填充它。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}
[thick
,decoration =
{markings
,mark=at position 0.5 with {\arrow{stealth'}}
}
]
 \newdimen\R     
 \R=2.7cm
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-160:{0.4*\R}) arc (-150:150:{0.4*\R});
 \foreach \x/\l in
{120/$x^2z^2$,
 240/$x^2y^2$,
 360/$y^2z^2$
}
\draw[postaction={decorate}] ({\x-120}:\R) -- node[auto,swap]{\l} (\x:\R);
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\end{tikzpicture}
\end{document}

TikZ 人物

答案1

要用某种颜色填充内部,您需要一条封闭的路径,例如使用

\draw[fill=pink] (0:\R)
  \foreach \x/\l in
    {120/$x^2z^2$,
     240/$x^2y^2$,
     360/$y^2z^2$
    }
  {-- node[auto,swap]{\l} (\x:\R)};

为了装饰这条路径的每个部分,我们可以使用以下技术这里

\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth'}}
      }}},
}
...
\draw[postaction={on each segment={mid arrow}},fill=pink] (0:\R)
... (continue like above)

当填充内部时,所有之前绘制在那里的东西都会被覆盖,所以我们必须将弧和中心标签的代码向下移动。

关于旋转,您必须决定标签是否应保持水平(选项)或者基线是否也应旋转,以便用倾斜的头部(整个 tikzpicture)rotate=90阅读。\rotatebox

在此处输入图片描述

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,arrows}
% From https://tex.stackexchange.com/a/69225
\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth'}}
      }}},
}
\begin{document}
\begin{tikzpicture}[thick,rotate=90]
 \newdimen\R     
 \R=2.7cm
\draw[postaction={on each segment={mid arrow}},fill=pink] (0:\R)
  \foreach \x/\l in
 {120/$x^2z^2$,
  240/$x^2y^2$,
  360/$y^2z^2$
 }
 {-- node[auto,swap]{\l} (\x:\R)};
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-150:{0.4*\R}) arc (-150:150:{0.4*\R});
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\end{tikzpicture}
\end{document}

答案2

你没有指定哪种颜色,所以我选择了粉色。请注意,TikZ 内部旋转不会影响上、下、左、右的规格。 \rotatebox旋转一切。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows,backgrounds}

\newdimen\SomeUniqueName% permanently uses up one register

\begin{document}
\rotatebox{90}{\begin{tikzpicture}
[thick
,decoration = {markings,mark=at position 0.5 with {\arrow{stealth'}}}
%,rotate=90% lines only
%,every node/.style={rotate=90}% text only
]
 \let\R=\SomeUniqueName% local to environment
 \R=2.7cm
  \node {$x^2y^2z^2$};
\draw[-stealth'] (-160:{0.4*\R}) arc (-150:150:{0.4*\R});
 \foreach \x/\l in
{120/$x^2z^2$,
 240/$x^2y^2$,
 360/$y^2z^2$
}
\draw[postaction={decorate}] ({\x-120}:\R) -- node[auto,swap]{\l} (\x:\R);
\foreach \x/\l/\p in
{ 
 120/{$x^2z$}/above,
 240/{$xy^2$}/below,
 360/{$yz^2$}/right
}
\node[inner sep=2pt,circle,draw,fill,label={\p:\l}] at (\x:\R) {};
\begin{scope}[on background layer]
  \fill[pink] (current bounding box.south west) rectangle (current bounding box.north east);
\end{scope}
\end{tikzpicture}}
\end{document}

演示

答案3

受@Zarko对我的其他解决方案的评论的启发,这里有一个更简单的解决方案,如果您不想将三角形​​推广到更复杂的结构,则更可取。请注意命名坐标的使用。如果您想旋转图片,只需修改三个坐标(也许还有一些标签的位置)。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}%
  [decoration    = {markings,mark=at position 0.5 with {\arrow{stealth'}}},
   vertex/.style = {inner sep=2pt,circle,draw,fill,label={#1}},
   edge/.style   = {postaction={decorate},thick}
  ]
  \newcommand\R{2.7}
  \coordinate (A) at (210:\R);
  \coordinate (B) at (330:\R);
  \coordinate (C) at (90:\R);
  \path[fill=pink] (A)--(B)--(C)--cycle;
  \draw[edge] (A) node[vertex={below:$x^2z$}]{} -- node[below]{$x^2y^2$} (B);
  \draw[edge] (B) node[vertex={below:$xy^2$}]{} -- node[right]{$y^2z^2$} (C);
  \draw[edge] (C) node[vertex={above:$yz^2$}]{} -- node[left ]{$x^2y^2$} (A);
  \node {$x^2y^2z^2$};
  \draw[-stealth',thick] (-150:{0.4*\R}) arc (-150:150:{0.4*\R});
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容