일부 노드를 통해 부드러운 곡선의 세그먼트에 레이블을 지정하려면 어떻게 해야 합니까?

일부 노드를 통해 부드러운 곡선의 세그먼트에 레이블을 지정하려면 어떻게 해야 합니까?

일부 노드(일부는 교차 라이브러리를 사용하여 계산됨)가 있고 해당 노드 중 일부를 통해 부드러운 곡선을 그려 각 노드 쌍 사이의 곡선에 레이블을 지정하려고 합니다.

\draw plot[smooth] coordinates {...}명령은 멋지고 부드러운 곡선을 그립니다. 해당 곡선의 세그먼트에 어떻게 레이블을 지정할 수 있습니까?

내가 생각해 낼 수 있는 유일한 해결 방법은 흰색으로 직선을 그리는 것입니다. 그러면 레이블만 표시됩니다. 그러나 더 나은 해결책이 있을 것이라고 확신합니다. 그렇게 하면 부드러운 곡선을 기준으로 레이블 위치가 크게 달라지기 때문입니다(예: 레이블 3은 곡선에서 멀리 떨어져 있는 반면 레이블 4는 매우 가깝습니다.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}

\begin{document}
\tikzstyle{vertex}=[circle,draw=black!30,fill=black!30,inner sep=1pt]
\begin{tikzpicture}[scale=2]

\node[vertex] (a) at (0,0) {};
\node[vertex] (b) at (2,-.3) {};
\node[vertex] (c) at (2.5, 1.3) {};
\node[vertex] (d) at (3.5, .6) {};
\node[vertex] (e) at (3, .2) {};

\draw (a) -- node[above,pos=.2] {1} (b) -- node[left] {2} (c) -- node[below left] {3} (d) -- node[below] {4} (e);
\draw[red] plot[smooth] coordinates {(a) (b) (c) (d) (e)};

\end{tikzpicture}
\end{document}

나의 시도

답변1

장식 을 사용할 수 있습니다 show path construction.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}
\newcounter{smoothcounter}
\begin{document}
\begin{tikzpicture}[scale=2,
    vertex/.style={circle,draw=black!30,fill=black!30,inner sep=1pt},
    label smooth/.style={decorate,decoration={show path construction,
        curveto code={
\path (\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast) 
coordinate[pos=0.4] (aux1) coordinate[pos=0.6] (aux2)
(aux1) to[edge label={$\stepcounter{smoothcounter}\arabic{smoothcounter}$}] (aux2);
}}
}]
  \node[vertex] (a) at (0,0) {};
  \node[vertex] (b) at (2,-.3) {};
  \node[vertex] (c) at (2.5, 1.3) {};
  \node[vertex] (d) at (3.5, .6) {};
  \node[vertex] (e) at (3, .2) {};
  \draw (a) -- node[above,pos=.2] {1} (b) -- node[left] {2} (c) -- node[below left] {3} (d) -- node[below] {4} (e);
  \setcounter{smoothcounter}{0}
  \draw[red,postaction=label smooth] plot[smooth] coordinates {(a) (b) (c) (d) (e)};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변2

당신이 사용에 너무 집착하지 않는다면 plot[smooth]다음을 사용할 수 있습니다hobby부드러운 곡선으로 좌표를 결합하는 TikZ 라이브러리입니다. 이렇게 하면 각 좌표 쌍 사이에 베지어 곡선이 생성되고 일반적인 방법으로 이러한 경로에 노드를 배치할 수 있습니다.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/570505/86}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}
\usetikzlibrary{hobby}

\begin{document}
\tikzstyle{vertex}=[circle,draw=black!30,fill=black!30,inner sep=1pt]
\begin{tikzpicture}[scale=2]

\node[vertex] (a) at (0,0) {};
\node[vertex] (b) at (2,-.3) {};
\node[vertex] (c) at (2.5, 1.3) {};
\node[vertex] (d) at (3.5, .6) {};
\node[vertex] (e) at (3, .2) {};

\draw[red,use Hobby shortcut,text=black] (a.center) .. node[auto] {\(1\)} (b.center) .. node[auto] {\(2\)} (c.center) .. node[auto] {\(3\)} (d.center) .. node[auto] {\(4\)} (e.center);



\end{tikzpicture}
\end{document}

레이블이 지정된 부드러운 곡선

관련 정보