答案1
有很多方法可以实现这一点,这里是其中一种。非常感谢 albert 向我解释这个问题!
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newcommand{\Runner}[2][]{
\addplot[no marks,thick,samples=2*#2+1,#1] {0.25*(1-cos(#2*x*360))};
\node[anchor=south,#1] at ({1/(2*#2)},0.5) {#2};
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=12cm,axis lines*=left,domain=0:1]
\Runner{1};
\Runner[blue]{3};
\end{axis}
\end{tikzpicture}
\end{document}
以下是您在评论中询问的内容。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newcommand{\Runner}[2][]{
\addplot[no marks,thick,samples=2*#2+1,#1] {0.25*(1-cos(#2*x*360))};
\node[anchor=south,#1] at ({1/(2*#2)},0.5) {#2};
}
\begin{document}
\begin{tikzpicture}[declare function={%
myisodd(\x)=mod(int(\x),2);
runner(\x,\y)=0.5*ifthenelse(myisodd(int(2*\y*\x)),1-(2*\y*\x-int(2*\y*\x)),
(2*\y*\x-int(2*\y*\x)));}]
\begin{axis}[width=12cm,axis lines*=left,domain=0:1]
\Runner{1};
\Runner[blue]{3};
\addplot[red,thick,samples=13] {min(runner(x,3),runner(x,1))};
\end{axis}
\end{tikzpicture}
\end{document}