使用 Tikz 绘制的机械振动图

使用 Tikz 绘制的机械振动图

我想画这个: 在此处输入图片描述 我成功地画出了这样的东西:

\documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}
    \begin{scope} [every node/.style={draw,outer sep=0pt,thick},place/.style={circle,fill=gray!20,thick,
inner sep=0pt,minimum size=6mm}]
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
\tikzstyle{damper}=[thick,decoration={markings,  
  mark connection node=dmp,
  mark=at position 0.5 with 
  {
    \node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
    \draw [thick] ($(dmp.north east)+(2.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
    \draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
  }
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.3cm,minimum height=0.3cm]
\draw[domain=0:11.5,variable=\t,samples=440,smooth]
        plot({(-\t+.1) r}:{\t/40+\t/10/(0.1+\t)});
\node (ground) [ground,anchor=north,minimum height=0.5cm] at ( 0.3,0.75) {};
\draw (ground.north east) -- (ground.south east);
\draw[ultra thick] (0,0)--(6,0);
\draw [spring] (6,0)--+(0,-2);
\node (gh) [ground,anchor=north,minimum width=1cm] at ( 6,-2) {};
\draw (gh.south east) -- (gh.south west);
\end{scope}

\end{tikzpicture}
\end{subfigure}

但事实并非如此!

在此处输入图片描述

你可以帮帮我吗?!

答案1

第一个提示应该是:LaTeX 不关心空格和回车符!整理你的绘图,事后理解会更好。虽然我不喜欢黄色条:

编辑

正如下面的 percusse 评论所说,使用\tikzstyle已被弃用,而是使用\tikzset来预先制作样式。

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

\tikzset{place/.style={  circle,
        fill=gray!20,
        thick,
        inner sep=0pt,
        minimum size=6mm},
        spring/.style={ decorate,
                        decoration={zigzag,
                                    pre length=0.3cm,
                                    post length=0.3cm,
                                    segment length=6,
                                    amplitude=6
                                    }
                      },
        damper/.style={ thick,
                        decoration={markings,
                                    mark connection node=dmp,
                                    mark=at position 0.5 with {\node (dmp) [thick,
                                                                            inner sep=0pt,
                                                                            transform shape,
                                                                            rotate=-90,
                                                                            minimum width=15pt,
                                                                            minimum height=3pt,
                                                                            draw=none] {};
                                                                \draw [thick] ($(dmp.north east)+(2.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
                                                                \draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
                                                                }
                                    },
                        decorate
                      },
        ground/.style={ fill,
                        pattern=north east lines,
                        draw=none,
                        minimum width=0.3cm,
                        minimum height=0.3cm
                      },
        bar/.style={fill=yellow,
                    draw=black,
                    minimum width=6cm,
                    minimum height=0.2cm,
                    anchor=west
                   }
    }

\begin{document}

\begin{tikzpicture}[>=latex,
                    every node/.style={outer sep = 0pt,
                                       thick
                                      }
                   ]
% Bar drawing with its labels
\node[bar] (Bar) at (0,0) {};
\node[anchor=south east] at (Bar.north east) {$m$};
\node[anchor=south] at (Bar.north) {$\ell$};
    % Theta angle in the middle
    \draw[->] (10:2.5) arc[start angle=10, delta angle=-20, radius=2.5] node[anchor=west]{$\theta$};
    % Neutral line and x axis
    \draw[dash dot] (Bar.west) -- ($(Bar.east)+(0.75cm,0)$) node(Xaxis){};
    \draw[thick,->] (Xaxis.center) -- +(0,-0.5cm)node[near end,anchor=west]{$x$};
% Spiral spring (damper) and its label
\draw[domain=0:11.5,variable=\t,samples=440,smooth] plot ({(-\t+.1) r}:{\t/40+\t/10/(0.1+\t)});
\node [anchor=south east, shift={(120:0.2)}] {$k_t$};
% Ground and its label
\node (Ground) [ground,anchor=north,minimum height=0.5cm] at ( 0.3,0.75) {};
\node[anchor=west] at (Ground.east) {$O$};
\draw (Ground.north east) -- (Ground.south east);
% Spring and its label
\draw [spring] (Bar.east) -- node[anchor=east,xshift=-0.5cm]{$k$} +(0,-2) node(EndSpring){};
% Spring base (other ground)
\node (SpringBase) [ground,anchor=north,minimum width=1cm] at (EndSpring) {};
\draw (SpringBase.south east) -- (SpringBase.south west);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

以下是一个例子:

\documentclass{standalone}
\usepackage{lmodern}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[very thick,fill=yellow](0.719,3.92) -- (5.92,3.92) -- (5.92,3.49) -- (0.719,3.49) -- cycle;
\draw (5.5,4.2) node{$m$};
\draw ((5.92/2+0.719/2,4.2) node {$\ell$};
\draw[dashdotted,thick](0.694,3.7) -- (6.56,3.7);
\draw[](0.741,3.7) .. controls (0.739,3.74) and (0.794,3.72) .. (0.808,3.71) .. controls (0.845,3.65) and (0.799,3.59) .. (0.749,3.57) .. controls (0.658,3.53) and (0.565,3.6) .. (0.542,3.69) .. controls (0.507,3.82) and (0.603,3.94) .. (0.726,3.97) .. controls (0.89,4) and (1.04,3.88) .. (1.07,3.72) .. controls (1.11,3.52) and (0.959,3.33) .. (0.764,3.3) .. controls (0.527,3.26) and (0.31,3.44) .. (0.276,3.68) .. controls (0.235,3.95) and (0.443,4.2) .. (0.711,4.23) .. controls (1.02,4.28) and (1.3,4.04) .. (1.34,3.74) .. controls (1.38,3.39) and (1.12,3.08) .. (0.779,3.04) .. controls (0.398,2.99) and (0.0532,3.28) .. (0.00979,3.66) .. controls (-0.0384,4.08) and (0.283,4.45) .. (0.696,4.5) .. controls (0.781,4.51) and (0.868,4.5) .. (0.952,4.49);
\draw (0,4.5) node{$k_t$};
\draw[thick,fill=blue](0.861,4.73) -- (1.03,4.73) -- (1.03,4.31) -- (0.861,4.31) -- cycle;
\draw (1.03,4.6) node[right] {$O$};
\draw[>=stealth,->](4.26,4.28) .. controls (4.85,4.28) and (4.86,3.12) .. (4.26,3.12)node [near end,right]{$\theta$};
\draw[very thick,>=stealth,->](6.56,3.7) -- (6.56,3.16) node[right]{$x$};
\draw[](5.92,3.49) -- (5.92,3.18) -- (6.22,3.1) -- (5.61,2.94) -- (6.21,2.79) -- (5.61,2.64) -- (6.21,2.48) -- (5.61,2.33) -- (6.21,2.18) -- (5.61,2.02) -- (6.21,1.87) -- (5.61,1.71) -- (6.21,1.56) -- (5.61,1.41) -- (6.21,1.25) -- (5.61,1.1) -- (6.21,0.944) -- (5.61,0.79) -- (6.21,0.636) -- (5.91,0.559) -- (5.91,0.251);
\draw[] (5.3,2) node[] {$k$};
\draw[thick](5.6,0.249) -- (6.23,0.249);
\draw[thin](5.59,0.173) -- (5.67,0.251);
\draw[thin](5.59,0.0535) -- (5.79,0.251);
\draw[thin](5.66,0.00368) -- (5.91,0.251);
\draw[thin](5.78,0.00368) -- (6.03,0.251);
\draw[thin](5.9,0.00368) -- (6.15,0.251);
\draw[thin](6.02,0.00368) -- (6.22,0.2);
\draw[thin](6.14,0.00368) -- (6.22,0.0805);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容