TikZ:让...无法解析该坐标?

TikZ:让...无法解析该坐标?

我不明白为什么?

\documentclass[tikz,margin=3pt]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc}
\usepackage{pgf}

\tikzset{%
    alamain/.style={%
    decoration={show path construction,%
    lineto code={
        \draw
        let % here his the faulty code ?
        \p1 = ($(\tikzinputsegmentlast)!.333!(\tikzinputsegmentfirst)
                             + (rnd*360:rnd*3pt)$),
        \p2 = ($(\tikzinputsegmentlast)!.666!(\tikzinputsegmentfirst)
                             + (rnd*360:rnd*3pt)$)
        in
        (\tikzinputsegmentfirst) .. controls \p1 and \p2 .. (\tikzinputsegmentlast) ;
        }
    },decorate
}}

\begin{document}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{tikzpicture}
\draw [help lines] grid (3,2);

\foreach \i in {0,...,10} {%
    \draw [alamain] (0,.2*\i) -- (3,.2*\i) ;
}

\end{tikzpicture}

\end{document}

答案1

以“曲线”方式延伸路径的一般语法是

<start point>.. controls <first control point> and <second control point> .. <end point>

和 点通常为 的形式(x,y)。如果您使用\p1来自 的\let操作,则应该(\p1)不是\p1

所以,你错过了括号

.. controls (\p1) and (\p2) ..

这有效:

\documentclass[tikz,margin=3pt]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc}
\usepackage{pgf}

\tikzset{%
    alamain/.style={%
    decoration={show path construction,%
    lineto code={
        \draw
        let % here his the faulty code ?
        \p1 = ($(\tikzinputsegmentlast)!.333!(\tikzinputsegmentfirst)
                             + (rnd*360:rnd*3pt)$),
        \p2 = ($(\tikzinputsegmentlast)!.666!(\tikzinputsegmentfirst)
                             + (rnd*360:rnd*3pt)$)
        in
        (\tikzinputsegmentfirst) .. controls (\p1) and (\p2) .. (\tikzinputsegmentlast) ;
        }
    },decorate
}}

\begin{document}
\pgfmathsetseed{\number\pdfrandomseed}
\begin{tikzpicture}
\draw [help lines] grid (3,2);

\foreach \i in {0,...,10} {%
    \draw [alamain] (0,.2*\i) -- (3,.2*\i) ;
}

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容