我想绘制一组节点/路径。但是,我懒得手动定位它们,我想指定它们沿给定路径的位置。我该怎么做?
这是我目前所做事情的图片。
但是,我希望点和标签遵循曲线路径而不是直线。
该图片由以下代码生成,但不幸的是,该代码依赖于一个小故障。也就是说,这只在\path
命令是两点之间的直线时才有效。如果我添加更多点,引导路径也会被绘制出来,这不是我的本意。
\begin{tikzpicture}
\draw (0,0) circle (2);
\path (135:2.2) node[anchor=east] {$Y$};
\def\mynode#1{node [pos=#1,after node path={(\tikzlastnode) +(0,-0.3) circle (0.05)}]}
\def\y#1#2{\mynode{#1} {$y_{#2}$}}
\path (0,-1) -- (-1.5,1.5)
\foreach \num/\pos in {1/0, 3/0.3, 5/0.53}
{\y{\pos}{\num}}
\foreach \pos in {0.7,0.75,0.8,0.82}
{\mynode{\pos} {}}
[fill];
\path (0,-1) -- (1.5,1.5)
\foreach \num/\pos in {2/0.2, 4/0.45}
{\y{\pos}{\num}}
\foreach \pos in {0.6,0.7,0.75,0.8,0.82}
{\mynode{\pos} {}}
[fill];
\end{tikzpicture}
答案1
你可能想看一下这个decorations.markings
库。它允许你沿路径在指定距离处执行任意代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
decoration={
markings,
mark=between positions 0.25 and 0.75 step 0.125 with {\node [yshift=0.3cm] {$y_\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}$};},
mark=between positions 0.125 and 0.875 step 0.125 with {\fill (0pt,0pt) circle (2pt);},
}
]
\path [postaction={decorate}] (0,0) .. controls (2,-1) .. (4,1) [in=40];
\end{tikzpicture}
\end{document}