
我想在用 TikZ 完成的节点中插入机械弹簧的符号。
这是我的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning}
\tikzset{
pinstyle/.style={pin edge={to-,thin,black}},
block/.style = {draw, rectangle,
minimum height=1cm,
align = center
% minimum width=2cm
},
input/.style = {coordinate,node distance=1cm},
output/.style = {coordinate,node distance=1cm},
arrow/.style={draw, -latex,node distance=2cm},
pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
sum/.style = {draw, circle, node distance=1cm},
gain/.style = {regular polygon, regular polygon sides=3,
draw, fill=white, text width=1em,
inner sep=0mm, outer sep=0mm,
shape border rotate=-90}
}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}[auto,>=latex',every node/.append style={font=\scriptsize}]
%DEFINIZIONE BLOCCHI
\node [input, name=input] {};
\node [sum, right=of input] (speed_sum) {};
\node [block, right=of speed_sum] (speed_controller) {$C_{\mathrm{vel}}(s)$};
\node [gain, right=2cm of speed_controller] (Kt) {$K_{t}$};
\node [block, right=of Kt] (gvm) {$G_{vM}(s)$};
\node [block, right=of gvm] (elastico) {$\frac{s\Theta_{M}(s)}{s\Theta_{C}(s)}$};
\node [output, right=of elastico] (output) {};
%DEFINIZIONE COLLEGAMENTI IN CATENA DIRETTA
\draw [->] (input) -- node {$\omega_{M}^{\mathrm{DES}}(s)$}(speed_sum);
\draw [->] (speed_sum) -- node {$E_{v}(s)$}(speed_controller);
\draw [->] (speed_controller) -- node {$I^{\mathrm{DES}}(s)=I(s)$}(Kt);
\draw [->] (Kt) -- node {$C_{\mathrm{M}}(s)$}(gvm);
\draw [->] (gvm) -- node [name=motor_speed] {$s\theta_{M}(s)$}(elastico);
\draw [->] (elastico) -- node [name=motor_speed] {$s\theta_{C}(s)$}(output);
%DEFINIZIONE COLLEGAMENTI FEEDBACK
\draw [->] (motor_speed) -- ++ (0,-2) -| node [pos=0.99] {$-$} (speed_sum);
\end{tikzpicture}
\end{center}
\caption{Anello di controllo di velocit\`a nel caso co-locato}
\label{fig:speed_loop_colocato}
\end{figure}
\end{document}
现在的输出如上(图中的第一个循环),但我想要如下所示的内容(图中的第二个循环):
正是我使用的地方
\node [block, right=of gvm] (elastico) {$\frac{s\Theta_{M}(s)}{s\Theta_{C}(s)}$};
我问的是是否有办法\textrm{SPRING_SYMBOL}
复制机械弹簧或者你会怎么做?
答案1
你可以用 TikZ 画出弹簧符号。我把它包装在一个宏中,以防你需要多次绘制弹簧,同时也使 TikZ 代码更简洁。
我还建议使用\centering
而不是\begin{center}
。
请注意,您可以更改几个选项来修改弹簧的外观。我将它们分别放在代码中的单独一行上,它们的作用应该很容易理解。如果没有,只需自己尝试一下数字即可。这些选项包括:segment length
、amplitude
和。当然pre length
,post length
锯齿线使用的坐标也可以修改。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning,decorations.pathmorphing} % <------- add new library
\newcommand*{\drawspring}{%
\tikz \draw[decorate,decoration={
zigzag,
segment length=0.2cm,
amplitude=2mm,
pre length=.1cm,
post length=.1cm}] (0,0)--(1,0);} % <-------- define a macro to draw the spring (for conciseness)
\tikzset{
pinstyle/.style={pin edge={to-,thin,black}},
block/.style = {draw, rectangle,
minimum height=1cm,
align = center
% minimum width=2cm
},
input/.style = {coordinate,node distance=1cm},
output/.style = {coordinate,node distance=1cm},
arrow/.style={draw, -latex,node distance=2cm},
pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
sum/.style = {draw, circle, node distance=1cm},
gain/.style = {regular polygon, regular polygon sides=3,
draw, fill=white, text width=1em,
inner sep=0mm, outer sep=0mm,
shape border rotate=-90}
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[auto,>=latex',every node/.append style={font=\scriptsize}]
%DEFINIZIONE BLOCCHI
\node [input,name=input] {};
\node [sum,right=of input] (speed_sum) {};
\node [block,right=of speed_sum] (speed_controller) {$C_{\mathrm{vel}}(s)$};
\node [gain, right=2cm of speed_controller] (Kt) {$K_{t}$};
\node [block, right=of Kt] (gvm) {$G_{vM}(s)$};
\node [block,right=of gvm] (elastico) {\drawspring}; % <--------- draw the spring here in the node
\node [output, right=of elastico] (output) {};
%DEFINIZIONE COLLEGAMENTI IN CATENA DIRETTA
\draw [->] (input) -- node {$\omega_{M}^{\mathrm{DES}}(s)$}(speed_sum);
\draw [->] (speed_sum) -- node {$E_{v}(s)$}(speed_controller);
\draw [->] (speed_controller) -- node {$I^{\mathrm{DES}}(s)=I(s)$}(Kt);
\draw [->] (Kt) -- node {$C_{\mathrm{M}}(s)$}(gvm);
\draw [->] (gvm) -- node [name=motor_speed] {$s\theta_{M}(s)$}(elastico);
\draw [->] (elastico) -- node [name=motor_speed] {$s\theta_{C}(s)$}(output);
%DEFINIZIONE COLLEGAMENTI FEEDBACK
\draw [->] (motor_speed) -- ++ (0,-2) -| node [pos=0.99] {$-$} (speed_sum);
\end{tikzpicture}
\caption{Anello di controllo di velocit\`a nel caso co-locato}
\label{fig:speed_loop_colocato}
\end{figure}
\end{document}
输出
答案2
对于线圈符号,请参阅以下答案:在 TikZ 中绘制机械弹簧
如果您想在其他地方重复该符号,请尝试在某处很好地绘制该符号,然后使用图片重新使用它:
\tikzset{ coil/.pic={
\draw (0.1,0) -- (0.2,1) -- (0.4,-1) -- (0.6,1) -- (0.8,-1) --(0.9,0) % and so on
}
}
然后将其与 一起使用\tikz (0,0) \draw pic{coil}
。如果您不需要调整其大小,效果很好。从您的问题来看,这似乎就是您想要的,只是以某种方式绘制的符号。您可以pic{coil}
像调用任何其他坐标一样在节点处调用 。