TikZ:使用 decorations.markings 来装饰剪切路径

TikZ:使用 decorations.markings 来装饰剪切路径

我沿着线剪了一个圆atan(2/3)。我想在剪圆的地方放一个箭头。我以为这很简单,只要(atan(2/3) + 180)/360得到它在路径上的百分比位置就行了。不幸的是,事实并非如此。我最终32.5因为反复试验而减去了度数。不过我想做一个更精确的位置。

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\angle}{atan(2/3)};
  \pgfmathsetmacro{\ppi}{\angle + 180};
  \pgfmathsetmacro{\percent}{(\ppi - 32.5)/360};

  \begin{scope}[rotate = \angle, decoration = {
      markings,
      mark = at position \percent with {\arrow{stealth}}
    }]
    \clip (0, .4) rectangle (-.45, 0);

    \draw[postaction = decorate] (cylinder) circle[radius = .395cm];
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

让我们分析一下。没有\clip旋转,没有绘制矩形,这是你的圆:

在此处输入图片描述

这表明该\percent值应该是50。使用

\pgfmathsetmacro{\ppi}{\angle + 180};
\pgfmathsetmacro{\percent}{(\ppi)/360};

你给的肯定不止50%这些。确切地说,你给的atan(2/3)更多\ppi。如果我们让\ppi= 180,那么\percent将是50

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\angle}{atan(2/3)};
  \pgfmathsetmacro{\ppi}{180};
  \pgfmathsetmacro{\percent}{(\ppi)/360};

  \begin{scope}[rotate = 0, decoration = {%     % change rotate to \angle
      markings,
      mark = at position \percent with {\arrow{stealth}}
    }]
    %\clip (0, .4) rectangle (-.45, 0);
    \draw (0, .4) rectangle (-.45, 0);

    \draw[postaction = decorate] (0,0) circle[radius = .395cm];
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

现在您可以旋转并剪辑以获得:

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\angle}{atan(2/3)};
  \pgfmathsetmacro{\ppi}{180};
  \pgfmathsetmacro{\percent}{(\ppi)/360};

  \begin{scope}[rotate = \angle, decoration = {
      markings,
      mark = at position \percent with {\arrow{stealth}}
    }]
    \clip (0, .4) rectangle (-.45, 0);
    %\draw (0, .4) rectangle (-.45, 0);

    \draw[postaction = decorate] (0,0) circle[radius = .395cm];
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容