更新

更新

我想要的是:

到有交叉点的节点的路径

其中黄线为需要变换的路径,黄线内的点为处理后的节点。

我发现实现此目的的唯一方法是路径与其本身的交集。但从处理和时间方面来看,这是一种昂贵的解决方案。生成上述图像的代码如下:

\documentclass[tikz]{standalone}

\usetikzlibrary{intersections}

\begin{document}
    \begin{tikzpicture} 

        \clip (-2.1, -1.1) rectangle (2.1, 1.1);
        \draw [yellow, ultra thick, name path = curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);

        \path [name intersections = {%
            of = curve 1 and curve 1
            , name = i
            , total=\t
            , sort by = curve 1
        }] node {\xdef\totalone{\t}};

        \foreach \k in {1, ..., \totalone}
        {
            \node [
                circle
                , fill
                , inner sep = 0.25pt
                , minimum size = 0pt
            ] at (i-\k) {};
        }

    \end{tikzpicture}
\end{document}

有人建议用另一种方法来实现这个目的吗?

答案1

您可能想查看一下decorations.markins图书馆。 (根据需要
调整点之间的步长(.5mm)和点的半径( )。.25pt

更新

经过此更新,您拥有的节点数(node0)(node203)\themynodes为您提供 204 个。 (如果您在命令前面
放置,它可以从 1 开始并以 204 结束。)\stepcounter{mynodes}\node

代码

\documentclass[tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\newcounter{mynodes}

\tikzset{dotteddecoration/.style={
    postaction={
        decorate,
        decoration={
            markings,
            mark=between positions 0 and 1 step .5mm with {
                \node[text=black,font=\fontsize{5}{5}\selectfont] (node\themynodes) at (0,0) {\themynodes};\stepcounter{mynodes}}
}}}}
\begin{document}
    \begin{tikzpicture}[]
        \clip (-2.1, -1.1) rectangle (2.1, 1.1);
        \draw [dotteddecoration, yellow, ultra thick] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
    \end{tikzpicture}
\end{document}

输出

输出:更新

旧解决方案

代码

\documentclass[tikz]{standalone}

\usetikzlibrary{decorations.markings}

\tikzset{dotteddecoration/.style={
    postaction={
        decorate,
        decoration={
            markings,
            mark=between positions 0 and 1 step .5mm with {
                \fill[#1] (0,0) circle (.25pt);}}}}}
\begin{document}
    \begin{tikzpicture}[]
        \clip (-2.1, -1.1) rectangle (2.1, 1.1);
        \draw [dotteddecoration=black, yellow, ultra thick] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
    \end{tikzpicture}
\end{document}

输出

输出

相关内容