我如何在以下 TikZ 绘图中在框 $M$ 下方绘制摩擦线……?
\begin{figure}[h]
\centering
\begin{tikzpicture} [font = \small]
% triangle:
\draw [draw = orange, fill = orange!15] (0,0) coordinate (O) -- (\ang:6)
coordinate [pos=.45] (M) |- coordinate (B) (O);
% angles:
\draw [draw = orange] (O) ++(.8,0) arc (0:\ang:0.8)
node [pos=.4, left] {$\theta$};
\draw [draw = orange] (B) rectangle ++(-0.3,0.3);
\begin{scope} [-latex,rotate=\ang]
% Object (rectangle)
\draw [fill = purple!30,
draw = purple!50] (M) rectangle node [] {$M$} ++ (1,.6) ;
\end{scope}
\end{tikzpicture}
\end{figure}
答案1
我不完全确定这是否是你想要的,但解决方案参考我的其他答案可能:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[font=\small]
\pgfmathsetmacro{\ang}{30}
% triangle:
\begin{scope}
\path[save path=\triangle, clip] (0,0) coordinate (O)
-- (\ang:6) coordinate[pos=.45] (M) |- coordinate (B) cycle;
\fill[orange!15] [use path=\triangle];
\fill[pattern=vertical lines, pattern color=orange!50] (O) -- (\ang:6) -- ++(0,-.25) -- (0,-.25) -- cycle;
\end{scope}
\draw[orange] [use path=\triangle];
% angles:
\draw[orange] (O) ++(.8,0) arc[start angle=0, end angle={\ang}, radius=0.8]
node[pos=.4, left, black] {$\theta$};
\draw[orange] (B) rectangle ++(-0.3,0.3);
\begin{scope}[rotate=\ang]
% Object (rectangle)
\draw[purple!50, fill=purple!30] (M) rectangle node[black] {$M$} ++(1,.6);
\end{scope}
\end{tikzpicture}
\end{document}
请注意,我使用了三次相同的路径:用图案裁剪形状、填充三角形并最终绘制轮廓。这可能不是最好的解决方案。
另一种解决方案可能是使用图案计算形状的精确坐标,如下所示:
\draw[orange, fill=orange!15] (0,0) coordinate (O)
-- (\ang:6) coordinate[pos=.45] (M) |- coordinate (B) cycle;
\fill[pattern=vertical lines, pattern color=orange!50] (O)
-- (\ang:6) -- ++(0,-.25) -- ({.25/tan(\ang)},0) -- cycle;
那么就不需要剪切和重新使用路径了。
正如@MS-SPO 指出的那样,您可能还想将摩擦线添加到矩形物体:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[font=\small]
\pgfmathsetmacro{\ang}{30}
% triangle:
\draw[orange, fill=orange!15] (0,0) coordinate (O)
-- (\ang:6) coordinate[pos=.45] (M) |- coordinate (B) cycle;
\fill[pattern=vertical lines, pattern color=orange!50] (O)
-- (\ang:6) -- ++(0,-.25) -- ({.25/tan(\ang)},0) -- cycle;
% angles:
\draw[orange] (O) ++(.8,0) arc[start angle=0, end angle={\ang}, radius=0.8]
node[pos=.4, left, black] {$\theta$};
\draw[orange] (B) rectangle ++(-0.3,0.3);
\begin{scope}[rotate=\ang]
% Object (rectangle)
\draw[purple!50, fill=purple!30] (M) rectangle node[black] {$M$} ++(1,.6);
\fill[pattern=vertical lines, pattern color=purple!45]
(M) rectangle ++(1,.25);
\end{scope}
\end{tikzpicture}
\end{document}