我非常喜欢使用 CircuiTikZ 在 LaTeX 文档中绘制图表。但是我主要绘制机械系统而不是电子系统,这就是为什么我正在寻找一些类似的方法来绘制机械系统。我想要的是绘制质量、弹簧、阻尼器和地面(边界条件)的东西。此处的图表(第 16 页)典型例子有:
有人有什么建议吗?还是我运气不好?
答案1
受到 Andrew Stacey 的精美绘画的启发,以下是您链接的两张图片的灵感。一旦您开始绘制此类内容,您就会很快积累自己的元素库,并且每次后续绘画都会变得更加容易。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\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)+(2pt,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.75cm,minimum height=0.3cm]
\node (M) [minimum width=3.5cm,minimum height=2cm] {mass, $m$};
\node (ground1) at (M.south) [ground,yshift=-1.5cm,xshift=-1.25cm,anchor=north] {};
\draw (ground1.north west) -- (ground1.north east);
\draw [spring] (ground1.north) -- ($(M.south east)!(ground1.north)!(M.south west)$);
\node (ground2) at (M.south) [ground,yshift=-1.5cm,anchor=north] {};
\draw (ground2.north west) -- (ground2.north east);
\draw [damper] (ground2.north) -- ($(M.south east)!(ground2.north)!(M.south west)$);
\node (ground3) at (M.south) [ground,yshift=-1.5cm,xshift=1.25cm,anchor=north] {};
\draw (ground3.north west) -- (ground3.north east);
\draw [spring] (ground3.north) -- ($(M.south east)!(ground3.north)!(M.south west)$);
\draw [-latex,ultra thick] (M.north) ++(0,0.2cm) -- +(0,1cm);
\begin{scope}[xshift=7cm]
\node (M) [minimum width=1cm, minimum height=2.5cm] {$m$};
\node (ground) [ground,anchor=north,yshift=-0.25cm,minimum width=1.5cm] at (M.south) {};
\draw (ground.north east) -- (ground.north west);
\draw [thick] (M.south west) ++ (0.2cm,-0.125cm) circle (0.125cm) (M.south east) ++ (-0.2cm,-0.125cm) circle (0.125cm);
\node (wall) [ground, rotate=-90, minimum width=3cm,yshift=-3cm] {};
\draw (wall.north east) -- (wall.north west);
\draw [spring] (wall.170) -- ($(M.north west)!(wall.170)!(M.south west)$);
\draw [damper] (wall.10) -- ($(M.north west)!(wall.10)!(M.south west)$);
\draw [-latex,ultra thick] (M.east) ++ (0.2cm,0) -- +(1cm,0);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
正如杰克所说,使用现有的 TikZ 工具绘制这些图形相当容易。这是我在讲座中使用的耦合摆的图表。
代码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\draw[ultra thick,blue] (0,0) -- (1,-3);
\fill[green!50!black] (1,-3) circle (.4);
\draw[->,thick,red!50!green] (1,-3) -- (-.5,-3.5);
\draw[ultra thick,blue] (0,0) -- (-2,-4);
\fill[green!50!black] (-2,-4) circle (.3);
\draw[->,thick,red!50!green] (-2,-4) -- (-1,-4.5);
\draw[thick,orange] (-1,-2) -- (-.8,-2) (.5,-2) -- (.667,-2);
\draw[thick,orange,decorate,decoration={coil,aspect=0.7,amplitude=5}] (-.8,-2) -- (.5,-2);
\draw[<->,thick,red!50!green] (-1,-2.5) -- (.667,-2.5);
\fill (0,0) circle (.2);
\end{tikzpicture}
\end{document}
需要注意的是弹簧。正如杰克在他的评论中所说,这是通过用线圈代替路径来实现的。
答案3
答案4
这可能会有所帮助。可以使用美国电阻器或可爱电感器作为弹簧,使用欧洲电阻器作为质量。
\documentclass{standalone}
\usepackage{circuitikz}
\makeatletter
% ************************* mechanical dashpot **************************
\ctikzset{bipoles/dashpot/height/.initial=.6}
\ctikzset{bipoles/dashpot/width/.initial=.8}
\pgfcircdeclarebipole{}
{\ctikzvalof{bipoles/dashpot/height}}
{dashpot}
{\ctikzvalof{bipoles/dashpot/height}}
{\ctikzvalof{bipoles/dashpot/width}}
{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfextractx{\pgf@circ@res@right}{\northeast}
\pgfextractx{\pgf@circ@res@left}{\southwest}
\pgfextracty{\pgf@circ@res@up}{\northeast}
\pgfextracty{\pgf@circ@res@down}{\southwest}
\pgfmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgflineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgflineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgflineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfmoveto{\pgfpoint{0}{0.9\pgf@circ@res@up}}
\pgflineto{\pgfpoint{0}{0.9\pgf@circ@res@down}}
\pgfusepath{draw}
\pgfsetlinewidth{\pgfstartlinewidth}
\pgfmoveto{\pgfpointorigin}
\pgflineto{\pgfpoint{\pgf@circ@res@right}{0}}
\pgfusepath{draw}
}
% create dashpot to-path style
\def\dashpotpath#1{\pgf@circ@bipole@path{dashpot}{#1}}
\compattikzset{dashpot/.style = {\circuitikzbasekey, /tikz/to path=\dashpotpath}}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (0,0) to[dashpot,o-*] (2,0);
\draw (3,1) to[dashpot,o-*] (3,-1);
\end{circuitikz}
\end{document}