\def \mypath { ... } 与 \path [name path = mypath] ... ;

\def \mypath { ... } 与 \path [name path = mypath] ... ;

这个问题是我最后一个问题。它涉及以某种方式命名路径的问题,以便能够对其执行操作,例如

  1. 平移或旋转它们
  2. 计算交叉点

为什么下面的代码会产生错误no shape pathone is known

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\path [name path = pathone]     (0,0) -- ++ (2,2) ;
\draw [ultra thick] (pathone) ;
\end{tikzpicture}
\end{document}

虽然这有效,但计算了交叉点,但不允许移动路径

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw [name path = pathone, ultra thick]     (0,0) -- ++ (2,2) ;
\draw [name path = pathtwo, ultra thick]     (0,0) ++ (-0.4,0) -- ++ (2.4,2.4) ;
\draw [name path = pathtre, ultra thick]     (0,0) arc (180:90:2) ;
\draw [name intersections={of=pathtwo and pathtre, by={a, b}}]
      (a) circle (2pt)
      (b) circle (4pt) ;
% \draw [shift={(1,0)}] (pathone) ;
\end{tikzpicture}
\end{document}

虽然此代码允许移动,但没有交叉点...

\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\def \pathone {(0,0) -- ++ (2,2)}
\def \pathtwo {(0,0) ++ (-0.4,0) -- ++ (2.4,2.4)}
\def \pathtre {(0,0) arc (180:90:2)}
\draw [ultra thick] \pathone ;
\draw [ultra thick] \pathtwo ;
\draw [ultra thick] \pathtre ;
% \draw [name intersections={of=\pathtwo and \pathtre, by={a, b}}]
%       (a) circle (2pt)
%       (b) circle (4pt) ;
\draw [ultra thick, shift={(1,0)}] \pathone ;
\end{tikzpicture}
\end{document}

这段代码完成了所有事情:

\begin{tikzpicture}
\def \pathone {(0,0) -- ++ (2,2)}
\def \pathtwo {(0,0) ++ (-0.4,0) -- ++ (2.4,2.4)}
\def \pathtre {(0,0) arc (180:90:2)}
\draw [ultra thick] \pathone ;
\draw [ultra thick, name path = pathtwo] \pathtwo ;
\draw [ultra thick, name path = pathtre] \pathtre ;
\draw [name intersections={of=pathtwo and pathtre, by={a, b}}]
        (a) circle (2pt)
        (b) circle (4pt);
\draw [ultra thick, shift={(1,0)}] \pathone ;
\end{tikzpicture}

  1. 做什么\path [name path = mypath] ... ;
  2. 是什么样的物体mypath(大概是一条路径)?
  3. mypath稍后如何召唤并对其进行操作?
  4. mypath为什么我不能稍后绘制路径,但可以用来mypath计算交点?
  5. 我什么时候应该使用\def \mypath { ... }
  6. 甚至是\mypath一条路吗?
  7. 为什么我可以操作\mypath(例如移动它)但似乎无法将它与其他路径相交?

最后我对这个问题感兴趣

如果我想稍后使用给定的路径、可能移动它等等,那么定义路径并为其命名的最佳方法是什么?

相关内容