路径上的标记点位置错误

路径上的标记点位置错误

我试着画一个图来表示同伦的作用。如你所见,曲线上的点位置不对。 在此处输入图片描述 梅威瑟:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=2]
    \node[] (a) at (0,0) {};
    \node[] (b) at (4,0) {};
    \draw[thick] (a) to[out=50,in=150]node[above]{$f(x)$} (b);
    \path [postaction={decorate},decoration={markings,mark = at position 0.5 with {\fill[red] circle[radius=1pt];}}] to[out=50,in=150] (b);
    
    \foreach \o/\i in {40/160,30/170,20/180,10/190,-10/200, -20/210}
       \draw[dashed] (a) to[out=\o,in=\i] (b);
    \draw[thick] (a) to[out=-20,in=-130]node[below]{$g(x)$} (b);
\end{tikzpicture}
\end{document}

答案1

您没有将(a)其用作装饰路径的起始节点:

\draw[thick] (a) to[out=50,in=150]node[above]{$f(x)$} (b);
\path[
  postaction={decorate},
  decoration={markings,mark=at position 0.5 with{\fill[red] circle[radius=1pt];}}]
                 to[out=50,in=150]                    (b);

TikZ 会(0, 0)在这里假设路径与绘制的路径略有不同。

(a)如果在点前面添加,to则会再次位于线上:

\draw[thick] (a) to[out=50,in=150]node[above]{$f(x)$} (b);
\path [
  postaction={decorate},
  decoration={markings,mark=at position 0.5 with{\fill[red] circle[radius=1pt];}}]
             (a) to[out=50,in=150]                    (b);
%            ↑↑↑

您可以直接装饰第一个图形并避免将来出现这种事故:

\draw[thick, mark with dot] (a) to[out=50,in=150]node[above]{$f(x)$} (b);

哪里mark with dot

\tikzset{
  mark with dot/.style={
    postaction=decorate,
    decoration={markings,mark=at position 0.5 with{\fill[red] circle[radius=1pt];}}
  }
}

这会将点放置在与节点略有不同的位置,f(x)因为节点位于时间曲线的一半处放置标记距离曲线。

也就是说,可以沿着路径放置一个简单的红点,

node[circle, fill=red, minimum size=+2pt, inner sep=+0pt]{}

如果它不仅仅是一个点,您还可以使用pic(可以像节点一样放置)。

代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
  mark with dot/.style={
    postaction=decorate,
    decoration={markings,mark = at position 0.5 with {\fill[red] circle[radius=1pt];}}
  },
  mark with dot'/.style={edge node={node[circle,fill=red,minimum size=+2pt,inner sep=+0pt]{}}},
  mark with dot''/.style={every to/.append style={mark with dot'}},
}
\begin{document}
\begin{tikzpicture}[scale=2]
    \node[] (a) at (0,0) {};
    \node[] (b) at (4,0) {};
    \draw[thick, mark with dot  ] (a) to[out=50,in=150]                 node[above]{$f(x)$} (b);
%    \draw[thick]                  (a) to[out=50,in=150, mark with dot'] node[above]{$f(x)$} (b);
%    \draw[thick, mark with dot''] (a) to[out=50,in=150]                 node[above]{$f(x)$} (b);
    
    \foreach \o/\i in {40/160,30/170,20/180,10/190,-10/200, -20/210}
       \draw[dashed] (a) to[out=\o,in=\i] (b);
    \draw[thick] (a) to[out=-20,in=-130]node[below]{$g(x)$} (b);
\end{tikzpicture}

\begin{tikzpicture}[scale=2]
    \node[] (a) at (0,0) {};
    \node[] (b) at (4,0) {};
    \draw[thick, mark with dot  ] (a) to[out=50,in=150] node[above]{$f(x)$} (b);
    
    \foreach \o/\i in {40/160,30/170,20/180,10/190,-10/200, -20/210}
       \draw[dashed, mark with dot] (a) to[out=\o,in=\i] (b);
    \draw[thick] (a) to[out=-20,in=-130]node[below]{$g(x)$} (b);
\end{tikzpicture}

\begin{tikzpicture}[scale=2]
    \node[] (a) at (0,0) {};
    \node[] (b) at (4,0) {};
    \draw[thick, mark with dot  ] (a) to[out=50,in=150] node[above]{$f(x)$} (b);
    
    \foreach \o/\i in {40/160,30/170,20/180,10/190,-10/200, -20/210}
       \draw[dashed, mark with dot''] (a) to[out=\o,in=\i] (b);
    \draw[thick] (a) to[out=-20,in=-130]node[below]{$g(x)$} (b);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容