使用 TikZ 绘制机械系统

使用 TikZ 绘制机械系统

这是在 LaTeX 中绘制机械系统。我曾尝试做类似的事情,例如,对简单的机械系统进行建模。

例如:

\begin{tikzpicture}[M1/.style={rectangle,draw=black,minimum size=2cm,thick}]

    \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=5}]
    \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm]
    \node [M1] (M1) {};
    \node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
    \draw (wall1.north west) -- (wall1.north east);
    \draw [spring] (wall1.170) -- ($(M1.south east)!(wall1.170)!(M1.south west)$) node[pos=.5,left] {$k_2$};
    \draw [spring] (wall1.10) -- ($(M1.south west)!(wall1.10)!(M1.south east)$) node[pos=.5,right] {$k_3$};
    \node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
    \draw (wall2.south west) -- (wall2.south east);
    \draw [spring] (wall2.170) -- ($(M1.north east)!(wall2.170)!(M1.north west)$) node[pos=.5,left] {$k_1$};
    \draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
    \filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
    \node [rotate=90,above] at (M1.west) {Mass,$m$};
    \node at (0,-3.5) {(a)};
        \begin{scope}[xshift=5cm]
            \node [M1] (M1) {};
            \node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
            \draw (wall1.north west) -- (wall1.north east);
            \draw [spring] (wall1) -- ($(M1.south east)!(wall1)!(M1.south west)$) node[pos=.5,left] {$k_2^*$};
            \node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
            \draw (wall2.south west) -- (wall2.south east);
            \draw [spring] (wall2) -- ($(M1.north east)!(wall2)!(M1.north west)$) node[pos=.5,left] {$k_1$};
            \draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
            \filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
            \node [rotate=90,above] at (M1.west) {Mass,$m$};
            \node at (0,-3.5) {(b)};
        \end{scope}
\end{tikzpicture}

现在我遇到了以下问题:

部分 a 中的弹簧 k1 已连接到墙壁,但连接到了错误的一侧。我尝试了几种方法,但都没有奏效。

关联:在 LaTeX 中绘制机械系统

图如下:

机械系统示例

答案1

您应该使用(wall2.190) -- ($(M1.north east)!(wall2.190)!(M1.north west)$)(请注意使用190而不是170)。第一个表达式指定弹簧的起点,在本例中位于墙的左下方。锚点指定节点边缘<node>.<number>上的点,其中数字指定放置锚点的角度。0是右边缘的中间,90是顶部的中间,170略高于左边缘的中间,并且190略低于左边缘的中间。第二个表达式指定弹簧的终点,它位于起点在从矩形的左上角到右上角的线上的投影(是在 上($(A)!(P)!(B)$)的投影)。PAB

机械系统

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}

\begin{tikzpicture}[M1/.style={rectangle,draw=black,minimum size=2cm,thick}]
    \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=5}]
    \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm]
    \node [M1] (M1) {};
    \node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
    \draw (wall1.north west) -- (wall1.north east);
    \draw [spring] (wall1.170) -- ($(M1.south east)!(wall1.170)!(M1.south west)$) node[pos=.5,left] {$k_2$};
    \draw [spring] (wall1.10) -- ($(M1.south west)!(wall1.10)!(M1.south east)$) node[pos=.5,right] {$k_3$};
    \node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
    \draw (wall2.south west) -- (wall2.south east);
    \draw [spring] (wall2.190) -- ($(M1.north east)!(wall2.190)!(M1.north west)$) node[pos=.5,left] {$k_1$};
    \draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
    \filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
    \node [rotate=90,above] at (M1.west) {Mass,$m$};
    \node at (0,-3.5) {(a)};
        \begin{scope}[xshift=5cm]
            \node [M1] (M1) {};
            \node (wall1) [ground, minimum width=3cm,yshift=-3cm] {};
            \draw (wall1.north west) -- (wall1.north east);
            \draw [spring] (wall1) -- ($(M1.south east)!(wall1)!(M1.south west)$) node[pos=.5,left] {$k_2^*$};
            \node (wall2) [ground, minimum width=3cm,yshift=3cm] {};
            \draw (wall2.south west) -- (wall2.south east);
            \draw [spring] (wall2) -- ($(M1.north east)!(wall2)!(M1.north west)$) node[pos=.5,left] {$k_1$};
            \draw [-latex,thick] (1.5,0) -- (1.5,1) node [pos=.5,right] {$x$};
            \filldraw circle (.05) node [pos=.5,below] {\tiny $CG$};
            \node [rotate=90,above] at (M1.west) {Mass,$m$};
            \node at (0,-3.5) {(b)};
        \end{scope}
\end{tikzpicture}


\end{document}

相关内容