我正在尝试使用 TikZ 绘制粗糙表面。这个问题 -自动生成显示粗糙表面上光扩散的图形- 解决同样的问题,并使用percusse 的这个答案我已经能够生成这个
不过,我想得到一个更像这样的图表(来源:接触表面.jpg从https://commons.wikimedia.org)
我怎样才能实现像这样的粗糙度轮廓?
代码
\documentclass[tikz,margin=3.14mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[fill=green!40!black!50!white]
{decorate[decoration={random steps,segment length=0.5mm,amplitude=1pt}] %Roughness is amplitude
{(0,0) -- ++(4,0)}} -- ++(0,-10mm) -- ++(-4cm,0) -- cycle;
\begin{scope}[yshift=0.1cm,yscale=-1]
\draw[fill=blue!40!black!50!white]
{decorate[decoration={random steps,segment length=0.5mm,amplitude=1pt}] %Roughness is amplitude
{(0,0) -- ++(4,0)}} -- ++(0,-10mm) -- ++(-4cm,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
答案1
带着jiggly
来自这个答案为了仅在 y 方向上产生随机性,可以使用适当的参数嵌套多个装饰,例如:
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\pgfdeclaredecoration{jiggly}{step}
{
\state{step}[width=+\pgfdecorationsegmentlength]
{\pgfmathsetmacro{\delta}{rand*\pgfdecorationsegmentamplitude}
\pgfpathlineto{
\pgfpointadd
{\pgfpoint{\pgfdecorationsegmentlength}{0pt}}
{\pgfpointpolar{90-\pgfdecoratedangle}
{\delta}}
}
}
\state{final}
{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}
\begin{document}
\begin{tikzpicture}[line join=round]
\draw[fill=green!40!black!50!white]
{decorate[decoration={jiggly, segment length=0.25,amplitude=0.25}]
{decorate[decoration={jiggly, segment length=1,amplitude=1}]
{decorate[decoration={jiggly, segment length=4,amplitude=4}]
{(0,0) -- ++(4,0)}}}} -- ++(0,-10mm) -- ++(-4cm,0) -- cycle;
\begin{scope}[yshift=0.5cm,yscale=-1]
\draw[fill=blue!40!black!50!white]
{decorate[decoration={jiggly, segment length=0.25,amplitude=0.25}]
{decorate[decoration={jiggly, segment length=1,amplitude=1}]
{decorate[decoration={jiggly, segment length=4,amplitude=4}]
{(0,0) -- ++(4,0)}}}} -- ++(0,-10mm) -- ++(-4cm,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}