随机平滑波与用户定义的平滑路径的叠加

随机平滑波与用户定义的平滑路径的叠加

我需要完成一个简单的任务,即在 Tikz 中向通常指定的平滑路径添加一些随机平滑扰动,如下图所示,以及一些用户定义的坐标。来自 Roland Ws 的回答 向路径添加垂直噪点 我了解到这可以用装饰器来完成。理想情况下,添加到路径的随机波的输入是波长和振幅。我知道这归结为只是在路径的每个第 n 个点的 x/y 值中添加一些随机性,但我不确定如何从下面的代码开始访问完整路径来执行此操作。有什么建议吗?

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\draw [thick, black,yshift=-100] plot [smooth, tension=1] coordinates {(1,1) (2.5,2) (3.5,1.5) (5,2) (5.5,1.5)};

\end{tikzpicture}
\end{document}

编辑:

我可以手动完成我想要的效果,但如下图所示,这非常繁琐。第一个绘图是我想要叠加扰动的粗糙平滑形状。第二个开始显示其中一些波浪,但显然很难处理。

\draw [thick, black] plot [smooth cycle, tension=0.75] coordinates { (-0.5,2.7) (0,2.75) (0.5,2.9) (1.0,2.95) (2.0,2.9) (2.5,2.95) (2.75,2.7) (2.8,2.5) (2.7,2.3) (2.65,2.1) (2.5,1.95) (2.4,1.8) (2.2,1.75) (2,1.8) (1.5,1.7) (1.2,1.9) (1,2.1) (0.7,2.3) (0.5,2.5) (0.3,2.55) (0,2.48) (-0.3,2.5) (-0.5,2.53) (-0.6,2.56) };

\draw [thick, black] plot [smooth cycle, tension=0.75] coordinates { (-0.5,2.7) (-0.25,2.65) (0,2.75) (0.25,2.92) (0.5,2.9) (0.62,2.99) (1.0,2.95) (1.5,2.88) (1.65,2.95) (1.72,2.97) (2.0,2.9) (2.5,2.95) (2.75,2.7) (2.85,2.5) (2.7,2.45) (2.65,2.1) (2.5,1.95) (2.38,1.91) (2.4,1.8) (2.2,1.75) (2,1.8) (1.75,1.75) (1.7,1.78) (1.5,1.7) (1.35,1.85) (1.2,1.9) (1.1,2) (1,2.1) (0.7,2.3) (0.5,2.5) (0.3,2.55) (0,2.48) (-0.3,2.5) (-0.5,2.53) (-0.6,2.56) };

答案1

这是一项临时提案。我遇到的问题是,通常的装饰效果往往不平滑。因此,在这个提案中,我沿曲线添加随机位移的坐标,然后通过平滑图将它们连接起来。

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing,patterns,decorations.markings}
\tikzset{random waves/.style args={#1and#2with name #3}{postaction={decorate,decoration={markings,
mark=at position 0.1 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-1);},
mark=at position 0.2 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-2);},
mark=at position 0.3 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-3);},
mark=at position 0.4 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-4);},
mark=at position 0.5 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-5);},
mark=at position 0.6 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-6);},
mark=at position 0.7 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-7);},
mark=at position 0.8 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-8);},
mark=at position 0.9 with {\coordinate[xshift={rand*#1},yshift={rand*#2}] (#3-9);}
}}}}
\begin{document}
\begin{tikzpicture}
\draw [thick, black,yshift=-100,random waves=1mm and 3mm with name pfft] plot [smooth, tension=1]
coordinates {(1,1) (2.5,2) (3.5,1.5) (5,2) (5.5,1.5)};

\draw [thick, blue,yshift=-100] plot [smooth, tension=0.5]
coordinates {(1,1) (pfft-1) (pfft-2) (pfft-3) (pfft-4)
(pfft-5) (pfft-6) (pfft-7) (pfft-8) (pfft-9) (5.5,1.5)};


\draw [thick, black,yshift=-200,random waves=1.1mm and 5mm with name pfft] plot [smooth, tension=1]
coordinates {(1,1) (2.5,2) (3.5,1.5) (5,2) (5.5,1.5)};

\draw [thick, blue,yshift=-200] plot [smooth, tension=0.5]
coordinates {(1,1) (pfft-1) (pfft-2) (pfft-3) (pfft-4)
(pfft-5) (pfft-6) (pfft-7) (pfft-8) (pfft-9) (5.5,1.5)};

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容