答案1
按照这些线条画一些东西并不太难。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\draw[decorate,decoration={markings,
mark=between positions 2mm and \pgfdecoratedpathlength-2mm step 2mm
with
{
\draw[ultra thick,gray]
(-3.5mm,-1.25mm) to[out=0,in=160] (-2mm,-1.25mm) to[out=-20,in=160]
(2mm,1.25mm) to[out=-20,in=180] (3.5mm,1.25mm);
}}]
(0,0) -- (4,-4);
\fill (0,0) circle (3mm);
\end{tikzpicture}
\end{document}
一种可以说更清洁的方法是使用装饰来实现。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations} % decorations.text just 4 fun
\pgfkeys{/tikz/.cd,
rope width/.store in=\RopeWidth,
rope width=5pt,
rope step/.store in=\RopeStep,
rope step=2mm,
}
\pgfdeclaredecoration{rope}{initial}
{%
\state{initial}[width=\RopeStep,next state=cont] {
\pgfmoveto{\pgfpoint{0pt}{-\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{5*\RopeStep/6}{0.25*\RopeWidth}}
{\pgfpoint{7*\RopeStep/6}{0.45*\RopeWidth}}
{\pgfpoint{1.5*\RopeStep}{\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{10*\RopeStep/6}{0.55*\RopeWidth}}
{\pgfpoint{11*\RopeStep/6}{0.6*\RopeWidth}}
{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
\pgfcoordinate{lastup}{\pgfpoint{-1.5*\RopeStep/6}{-\RopeWidth/2}}
}
\state{cont}[width=\RopeStep]{
\pgfmoveto{\pgfpointanchor{lastup}{center}}
\pgfpathcurveto
{\pgfpoint{-5*\RopeStep/6}{-0.6*\RopeWidth}}
{\pgfpoint{-4*\RopeStep/6}{-0.55*\RopeWidth}}
{\pgfpoint{-3*\RopeStep/6}{-0.55*\RopeWidth}}
\pgfpathcurveto
{\pgfpoint{-\RopeStep/6}{-0.45*\RopeWidth}}
{\pgfpoint{\RopeStep/6}{-0.25*\RopeWidth}}
{\pgfpoint{3*\RopeStep/6}{0pt}}
\pgfpathcurveto
{\pgfpoint{5*\RopeStep/6}{0.25*\RopeWidth}}
{\pgfpoint{7*\RopeStep/6}{0.45*\RopeWidth}}
{\pgfpoint{9*\RopeStep/6}{\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{10*\RopeStep/6}{0.55*\RopeWidth}}
{\pgfpoint{11*\RopeStep/6}{0.6*\RopeWidth}}
{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
\pgfcoordinate{lastup}{\pgfpoint{-1.5*\RopeStep/6}{-\RopeWidth/2}}
}
\state{final}[width=5pt]
{
\pgfmoveto{\pgfpointanchor{lastup}{center}}
\pgfpathcurveto
{\pgfpoint{-5*\RopeStep/6}{-0.6*\RopeWidth}}
{\pgfpoint{-4*\RopeStep/6}{-0.55*\RopeWidth}}
{\pgfpoint{-0.5*\RopeStep}{-0.55*\RopeWidth}}
\pgfpathcurveto
{\pgfpoint{-\RopeStep/6}{-0.45*\RopeWidth}}
{\pgfpoint{\RopeStep/6}{-0.25*\RopeWidth}}
{\pgfpoint{0.5*\RopeStep}{0pt}}
\pgfmoveto{\pgfpointdecoratedpathlast}
}
}
\begin{document}
\begin{tikzpicture}[decoration=rope]
\draw[red,thick,decorate,rope width=8pt] (-4,0) to[out=0,in=90] (0,-4);
\draw[gray,thick,decorate] (0,0) to (4,-4);
\draw[blue,ultra thick,decorate,rope width=8pt] (4,0) to (8,-4);
\fill (-4,0) circle (8pt) (0,0) circle (8pt) (4,0) circle (8pt);
\end{tikzpicture}
\end{document}
这些装饰都有待改进,特别是沿着弯曲路径的装饰有一些小的缝隙。
附录:这是没有缝隙的版本。但是曲率大的时候看起来不太好看。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations} % decorations.text just 4 fun
\newcounter{ropept}
\pgfkeys{/tikz/.cd,
rope width/.store in=\RopeWidth,
rope width=5pt,
rope step/.store in=\RopeStep,
rope step=2mm,
}
\pgfdeclaredecoration{rope}{initial}
{%
\state{initial}[width=\RopeStep,next state=cont] {
\pgfmoveto{\pgfpoint{0pt}{-\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{5*\RopeStep/6}{0.25*\RopeWidth}}
{\pgfpoint{7*\RopeStep/6}{0.45*\RopeWidth}}
{\pgfpoint{1.5*\RopeStep}{\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{10*\RopeStep/6}{0.55*\RopeWidth}}
{\pgfpoint{11*\RopeStep/6}{0.6*\RopeWidth}}
{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
\setcounter{ropept}{0}
\pgfcoordinate{lastup-\theropept}{\pgfpoint{-1.5*\RopeStep/6}{-\RopeWidth/2}}
\pgfcoordinate{rope-auxA-\theropept}{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
}
\state{cont}[width=\RopeStep]{
\pgfmoveto{\pgfpointanchor{lastup-\theropept}{center}}
\pgfpathcurveto
{\pgfpoint{-5*\RopeStep/6}{-0.6*\RopeWidth}}
{\pgfpoint{-4*\RopeStep/6}{-0.55*\RopeWidth}}
{\pgfpoint{-3*\RopeStep/6}{-0.55*\RopeWidth}}
\pgfpathcurveto
{\pgfpoint{-\RopeStep/6}{-0.45*\RopeWidth}}
{\pgfpoint{\RopeStep/6}{-0.25*\RopeWidth}}
{\pgfpoint{3*\RopeStep/6}{0pt}}
\pgfpathcurveto
{\pgfpoint{5*\RopeStep/6}{0.25*\RopeWidth}}
{\pgfpoint{7*\RopeStep/6}{0.45*\RopeWidth}}
{\pgfpoint{9*\RopeStep/6}{\RopeWidth/2}}
\pgfpathcurveto
{\pgfpoint{10*\RopeStep/6}{0.55*\RopeWidth}}
{\pgfpoint{11*\RopeStep/6}{0.6*\RopeWidth}}
{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
\pgfmoveto{\pgfpointanchor{rope-auxA-\theropept}{center}}
\pgfpathlineto{\pgfpoint{9*\RopeStep/6}{\RopeWidth/2}}
\stepcounter{ropept}
\pgfcoordinate{lastup-\theropept}{\pgfpoint{-1.5*\RopeStep/6}{-\RopeWidth/2}}
\pgfcoordinate{rope-auxA-\theropept}{\pgfpoint{13.5*\RopeStep/6}{\RopeWidth/2}}
}
\state{final}[width=5pt]
{
\pgfmoveto{\pgfpointanchor{lastup-\theropept}{center}}
\pgfpathcurveto
{\pgfpoint{-5*\RopeStep/6}{-0.6*\RopeWidth}}
{\pgfpoint{-4*\RopeStep/6}{-0.55*\RopeWidth}}
{\pgfpoint{-0.5*\RopeStep}{-0.55*\RopeWidth}}
\pgfpathcurveto
{\pgfpoint{-\RopeStep/6}{-0.45*\RopeWidth}}
{\pgfpoint{\RopeStep/6}{-0.25*\RopeWidth}}
{\pgfpoint{0.5*\RopeStep}{0pt}}
\pgfmoveto{\pgfpointdecoratedpathlast}
\xdef\LastRope{\theropept}
}
}
\begin{document}
\begin{tikzpicture}[decoration=rope]
\draw[decorate] plot[smooth cycle, fill=yellow, thick] coordinates{ (4.,8.4) (6.5,9.) (8.,9) (9.,8.1) (11.34,6.18) (11,4) (11.3,2.2) (10.2 7,0.7 ) (8. 4,0.14) (6.2,0.29) (4.40,0.51) (3.2,0.29) (1.5,0.34) } ;
\typeout{\theropept}
\end{tikzpicture}
\end{document}