Tikz Intersecion 无法识别名称为 path 的路径

Tikz Intersecion 无法识别名称为 path 的路径

即使在同一个循环中,使用定义的路径名也会出现问题。以下代码会产生错误消息:

 ! Package tikz Error: I do not know the path named `ab6'. Perhaps you misspelt it.

代码:

\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows,chains,positioning,intersections}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{tikz-3dplot}
%
%
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\begin{document}
%
\center
\tdplotsetmaincoords{47}{5}
\begin{tikzpicture}[scale=4,tdplot_main_coords]
\foreach\i in {0,...,6}
{\tdplotsetcoord{A\i}{1}{8+51.4*\i}{0};
\coordinate(B\i) at ([shift={(0,1.2,0)}]A\i);}
\foreach \k[evaluate=\k as \ki using {int(mod(\k+3,7))}] in {0,...,6}
{\path[%draw%
,thick,name path = pa\k](A\k)--(A\ki);
\path[%draw%
,thick,name path = pb\k](B\k)--(B\ki);
}
\foreach \j in {0,...,6}
{%\node at (C\j){$C_\j$};
\node at (A\j){$A_\j$};
%\node at (D\j){$D_\j$};
\node at (B\j){$B_\j$};
}
\foreach \j[evaluate={\ja={int(mod(\j+2,7))};\jc={int(mod(\j+6,7))}}] in  {0,...,6}
{
\path[name path=ba\j,draw](B\j)--(A\ja);
\path[name path=ab\j,draw](A\j)--(B\ja);
\path[name intersections={of={ba\j} and {ab\jc},by={C\j}}];
}
%\path[name intersections={of={ba0} and {ab6},by={C0}}]
\end{tikzpicture}
\end{document}

我试过了

name path global

name path globa/.expanded

但都没有用。当我注释掉导致这个问题的行并取消注释时

\path[name intersections={of={ba0} and {ab6},by={C0}}]

然后 TikZ 说它不知道名为“ba0”的路径。

答案1

在循环的第一次迭代中\j是 0,但是\jc是 6,而你正在尝试执行

  \path[name intersections={of={ba\j} and {ab\jc},by={C\j}}];

即寻找ba0和的交点ab6,但ab6尚不存在。使用两个单独的循环:

\documentclass[12pt]{article}
\pagestyle{empty}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows,chains,positioning,intersections}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage{tikz-3dplot}

\begin{document}

\tdplotsetmaincoords{47}{5}
\begin{tikzpicture}[scale=4,tdplot_main_coords]
\foreach\i in {0,...,6}
{\tdplotsetcoord{A\i}{1}{8+51.4*\i}{0};
\coordinate(B\i) at ([shift={(0,1.2,0)}]A\i);}
\foreach \k[evaluate=\k as \ki using {int(mod(\k+3,7))}] in {0,...,6}
{\path[%draw%
,thick,name path = pa\k](A\k)--(A\ki);
\path[%draw%
,thick,name path = pb\k](B\k)--(B\ki);
}
\foreach \j in {0,...,6}
{%\node at (C\j){$C_\j$};
\node at (A\j){$A_\j$};
%\node at (D\j){$D_\j$};
\node at (B\j){$B_\j$};
}

\foreach \j [evaluate={\ja={int(mod(\j+2,7))};\jc={int(mod(\j+6,7))}}] in  {0,...,6}
{
\path[name path global=ba\j,draw](B\j)--(A\ja);
\path[name path global=ab\j,draw](A\j)--(B\ja);
}

\foreach \j [evaluate={\ja={int(mod(\j+2,7))};\jc={int(mod(\j+6,7))}}] in  {0,...,6}
  \path[name intersections={of={ba\j} and {ab\jc},by={C\j}}];

\path[name intersections={of={ba0} and {ab6},by={C0}}];
\end{tikzpicture}

\end{document}

相关内容