我在用这代码来生成双摆的图像。但我想分别用 $l_{2}$ 和 $m_{2}$ 重新标记下部连杆和下部质量。我尝试了不同的方法来做到这一点,但未能以所需的方式编译文件。有人能帮我吗?谢谢。
答案1
通过解开循环,我最终得到了以下代码:
\documentclass[tikz,border=8mm]{standalone}
\usetikzlibrary{backgrounds,angles,quotes}
\begin{document}
\begin{tikzpicture}[%
angle eccentricity=1.2,
ball/.style={circle, inner sep=0pt, minimum size=2mm, fill=blue, draw=blue},
background rectangle/.style={fill=black},
show background rectangle]
\draw[thick, white] (-2,0) --(2,0);
\draw[white] (0,0) coordinate (b0) -- ++(-70:2cm) node[midway,auto]{$l$} node[ball, label=right:$m$] (b1) {} --++(-55:2cm) node[midway,auto]{$l_2$} node[ball, label=right:$m_2$] (b2) {};
\draw[dashed, white] (b0)--++(-90:1.8cm) coordinate[pos=.75] (aux1);
\draw[dashed, white] (b1)--++(-90:1.8cm) coordinate[pos=.75] (aux2);
\draw pic["$\theta_1$", draw, white, angle radius=1.2cm] {angle=aux1--b0--b1};
\draw pic["$\theta_2$", draw, white, angle radius=1.2cm] {angle=aux2--b1--b2};
\end{tikzpicture}
\end{document}
按照评论中@leandriis 的建议,您可以这样做:
\documentclass[tikz,border=8mm]{standalone}
\usetikzlibrary{backgrounds,angles,quotes}
\begin{document}
\begin{tikzpicture}[%
angle eccentricity=1.2,
ball/.style={circle, inner sep=0pt, minimum size=2mm, fill=blue, draw=blue, label=right:$m_{\ni}$},
background rectangle/.style={fill=black},
show background rectangle]
\draw[thick, white] (-2,0) --(2,0);
\draw[white] (0,0) coordinate (b0) foreach \i [count=\ni] in {-70,-55} {--++(\i:2cm) node[midway,auto]{$l_{\ni}$} node[ball] (b\ni) {}};
\foreach \i [count=\auxi] in {b0,b1}{
\draw[dashed, white] (\i)--++(-90:1.8cm) coordinate[pos=.75] (aux\auxi);
}
\draw pic["$\theta_1$", draw, white, angle radius=1.2cm] {angle=aux1--b0--b1};
\draw pic["$\theta_2$", draw, white, angle radius=1.2cm] {angle=aux2--b1--b2};
\end{tikzpicture}
\end{document}