如何使用 tikz 装饰来改善路径?

如何使用 tikz 装饰来改善路径?

我是 LaTeX 的初学者,试图绘制一系列接近工程图的草图,以说明控制两块金属推在一起的收缩阻力的方程。一个典型的例子是用螺栓固定在接线端子上的端子舌片。MWE 显示了镀锡铜舌的横截面,其中央有一个用于螺栓固定的孔。一个关键因素是导电表面的粗糙度,当用螺栓固定时,导电表面会表现出塑性和弹性变形的组合。我想增强代码(大部分是借用的),以便黑线受到与顶部和底部表面相同的粗糙度的影响。(并像形状的轮廓一样变成灰色,但由于镀层没有在该区域分段,因此变得更薄)。我尝试了各种方法来做到这一点,但都没有得到令人满意的结果。

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\definecolor{copper}{rgb}{0.69, 0.25, 0.21}
\definecolor{tin}{rgb}{0.7, 0.7, 0.7}

\begin{document}
\begin{tikzpicture}
\draw[ultra thick]
(3,0)--(6,0);
\draw[ultra thick]
(3,2)--(6,2);
\draw[ultra thick, tin, fill=copper]
(0,0)--(0,2) 
\pgfextra{\pgfmathsetseed{10}}
decorate[decoration={random steps,segment length=0.2cm,amplitude=.05cm, }]
{-- (3,2)} -- (3,0) 
\pgfextra{\pgfmathsetseed{12}}
decorate[decoration={random steps,segment length=0.2cm,amplitude=.05cm}]
{-- (0,0)};
\draw[ultra thick, tin, fill=copper]
(6,0)--(6,2) 
\pgfextra{\pgfmathsetseed{14}}
decorate[decoration={random steps,segment length=0.2cm,amplitude=.05cm}]
{-- (9,2)} -- (9,0) 
\pgfextra{\pgfmathsetseed{11}}
decorate[decoration={random steps,segment length=0.2cm,amplitude=.05cm}]
{-- (6,0)};
\end{tikzpicture}
\end{document}

答案1

我不知道你想要的是不是这个,但希望这会对你有所帮助。

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\definecolor{copper}{rgb}{0.69, 0.25, 0.21}
\definecolor{tin}{rgb}{0.7, 0.7, 0.7}

\tikzset{
  rugous/.style = {tin, thick,
    decoration={random steps,segment length=0.2cm,amplitude=.05cm}
  },
  rugous block/.style = {rugous, fill=copper, ultra thick},
}

\begin{document}
  \begin{tikzpicture}
    \draw[rugous,decorate] (3,0) -- (6,0);
    \draw[rugous,decorate] (3,2) -- (6,2);
    \filldraw[rugous block]
      (0,0) -- ++(0,2) decorate{-- ++(3,0)} -- ++(0,-2) decorate{-- ++(-3,0)};
    \filldraw[rugous block]
      (6,0) -- ++(0,2) decorate{-- ++(3,0)} -- ++(0,-2) decorate{-- ++(-3,0)};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容