此代码的最后一个 \foreach 存在问题:无法编译

此代码的最后一个 \foreach 存在问题:无法编译
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfmath}
\usetikzlibrary{calc,intersections,through,backgrounds}

\begin{document}


\begin{tikzpicture}[scale=2]
\draw[step=5mm, gray, very thin] (-4,-4) grid (4,4) ;
\draw[thin, blue] (-3,0) -- (3,0) ;
\draw[thin, blue] (0,-3) -- (0,3) ;

\draw (2.5,0) -- (1.5,2) -- (0,0);
\draw[dotted] (1.5,1) -- (1.5,2) ;
\draw[dotted] (0,0) -- (1.5,1) ;
\draw (0,0) -- (-0.5,1.5) -- (1.5,2) ;
\draw (0,0) -- (2,-1) -- (2.5,0) ;
\draw[dashed] (0,0) -- (2.5,0) ;
\draw (2,-1) -- (1.5,2) ;
\draw (0,0) -- (0.5,-1) -- (2,-1) ;
\path [name path = ligne1] (0.5,-1) -- (2.5,0) ;
\path [name path = ligne2] (0,0) -- (2,-1) ;
\path [name intersections={of= ligne1 and ligne2, by={ x12 }}];
\draw[dashed] (0.5,-1) -- (x12) ;
\draw[dotted] (x12) -- (2.5,0) ;
\path [name path = ligne3] (1.5,1) -- (0.5,-1) ;
\path [name intersections={of= ligne2 and ligne3, by={ x23 }}];
\draw[dashed] (0.5,-1) -- (x23) ;
\draw[dotted] (x23) -- (1.5,1) ;
\draw (-0.5,1.5) -- (-0.5,0.25) -- (0.5,-1) ;
\path [name path = ligne4] (-0.5,0.25) -- (1.5,1) ;
\path [name path = ligne5] (0,0) -- (-0.5,1.5) ;
\path [name path = ligne6] (0,0) -- (1.5,2) ;
\path [name intersections={of= ligne4 and ligne5, by={ x45 }}];
\path [name intersections={of= ligne4 and ligne6, by={ x46 }}];
\draw[dashed] (-0.5,0.25) -- (x45) ;
\draw[dashed] (x45) -- (x46)(1.5,1) ;
\draw[dotted] (x46) -- (1.5,1) ;
\draw (0,0) -- (-0.5,0.25) ;
\path [name path = ligne7] (2,-1) -- (1.5,2) ;
\path [name path = ligne8] (2.5,0) -- (1.5,1) ;
\path [name intersections={of= ligne7 and ligne8, by={ x78 }}];
\draw[dotted] (2.5,0) -- (x78) ;
\draw[dotted ] (x78) -- (1.5,1) ;
\path [name path = ligne9] (-0.5,1.5) -- (1.5,1) ;
\path [name intersections={of= ligne6 and ligne9, by={ x69 }}];
\draw[dashed] (-0.5,1.5) -- (x69) ;
\draw[dotted] (x69) -- (1.5,1) ;
\path [name path = ligne10] (0,0) -- (2.5,0) ;
\path [name path=cercle1] (0,0) circle [radius = 1] ;
\path [name intersections={of= ligne10 and cercle1, by={ a }}];
\path [name intersections={of= ligne6 and cercle1, by={ b }}];
\path [name path = ligne11] (2.5,0) -- (1.5,2) ;

\foreach \n in {0,1,2,3,4,5,6,7,8,9,10}
    {\path [name path = div1\n] (0,0) -- ({2.5 -(1*\n)/10},{(2*\n)/10}) ;
     \path [name intersections={of= cercle1 and div1\n, by={ a\n }}] ;


        } ;

\draw[blue,smooth, name path = arca] plot coordinates {(a0) (a1) (a2) (a3) (a4) (a5) (a6) (a7) (a8) (a9) (a10)} ;

\path[name path = cercle2] (0,0) circle [x radius = 1cm, y radius =0.4cm] ;
\foreach \n in {0,1,2,3,4,5,6,7,8,9,10}
{\path [name path = div2\n] (0,0) -- ({2.5 -(1*\n)/10},{(1*\n)/10}) ;
    \path [name intersections={of= cercle2 and div2\n, by={ b\n }}] ;
} ;
\draw[green,smooth, name path = arcb] plot coordinates {(b0) (b1) (b2) (b3) (b4) (b5) (b6) (b7) (b8) (b9) (b10)} ;

\path [name path=prearcc] (a10) -- (b10) ;
\coordinate (c) at ($(a10)!0.5!(b10)$) ;


\draw [name path = cercle3]
      let \p1 = ($ (a10) - (c) $),
          \n2 = {veclen(\x1,\y1)}
      in
          (c) circle [x radius = 0.25mm, y radius = \n2,rotate = -11]    ;


\coordinate (c') at ($(a10) - (b10)$) ;
\coordinate (c'') at ($0.1*(c')$) ;


\foreach \i in {0,1,2,3,4,5,6,7,8,9,10}
{\path [draw,red,name path = divnew\i] (c) -- ($ { \i * (c'')} $) ;
    \path [name intersections={of= cercle3 and divnew\i, by={ c\i }}] ;
} ;

\end{tikzpicture}
\end{document}

答案1

我感到很紧张,无法发表评论,但是......只是为了丰富这个答案。

在 TeX 的第一门课程中,我们学习到如果出现错误,请添加括号。例如$10^10$。然而 TiZ 的工作方式不同。正如 @percusse 解释的那样这个答案,Ti 的核心Z 反复检查下一个字符并决定下一步做什么。如果遇到无用的括号,它将不起作用。所以这是第一课:除非必要,否则不要添加括号。

然后,TiZ 使用 TeX 功能检查您的拼写。借用@percusse 的例子:

def\tikz@collect@coordinate@onpath@#1oordinate{%
  \pgfutil@ifnextchar[{\tikz@@collect@coordinate@opt#1}{\tikz@@collect@coordinate@opt#1[]}}%}

类似地,在tikzlibrarycalc.code.tex其中定义:

\def\tikz@cc@parse@factor#1*({%
  \pgfmathparse{#1*\tikz@cc@factor}%
  \let\tikz@cc@factor=\pgfmathresult%
  \tikz@cc@coordinate(%)
}

这是第二课:不要添加空格,除非必要的

相关内容