如何绘制不同压缩率的线圈

如何绘制不同压缩率的线圈

我正在尝试绘制一个具有不同压缩率的线圈,沿着下面的图片(不是我的)的线。在此处输入图片描述

我考虑过把两个不同压缩比的线圈并排画出来

\usetikzlibrary{decorations.pathmorphing,patterns}
\begin{tikzpicture}
\draw[decoration={aspect=0.3, segment length=4mm, amplitude=4mm,coil},decorate] (0,0) 
-- (2,0); 
\draw[decoration={aspect=0.3, segment length=2mm, amplitude=4mm,coil},decorate] (0,0) 
-- (-2,0); 
\end{tikzpicture}

结果是:在此处输入图片描述

但从压缩线圈到非压缩线圈的过渡并不十分顺利。有人知道如何解决这个问题吗?

答案1

这只是一个疯狂的建议(有点碰运气,因为我没有时间找出正确的数字,但是......)。

你可以画一个恒定大小的线圈使用余弦函数扭曲 x 坐标。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\mytransformation{%
    \pgfmathsetmacro{\myX}{\pgf@x + 2*cos(\pgf@x*8)}%
    % no need to change y --- let's comment this out
    % \pgfmathsetmacro{\myY}{\pgf@y}
    \setlength{\pgf@x}{\myX pt}%
    % \setlength{\pgf@y}{\myY pt}
}
\makeatother\begin{document}
\begin{tikzpicture}
    \begin{scope}
        \pgftransformnonlinear{\mytransformation}
        \draw[decoration={aspect=0.3, segment length=2mm, amplitude=4mm,coil},decorate]
            (0,0) -- (10,0);
    \end{scope}
\end{tikzpicture}
\end{document}

余弦调制线圈

答案2

完成 Rmano 答案后我提出以下代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\mytransformation{%
\pgfmathsetmacro{\myX}{\pgf@x + 2*cos(\pgf@x*8)}
%\pgfmathsetmacro{\myY}{\pgf@y}
\setlength{\pgf@x}{\myX pt}
%\setlength{\pgf@y}{\myY pt}
}
\makeatother
\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \pgftransformnonlinear{\mytransformation}
            \draw[cyan,line width=1pt,decoration={aspect=0.3, segment length=2.5mm, amplitude=4mm,coil},decorate]
                (0,0) -- (10,0);
        \end{scope}
        \draw (0,-.5) -- (10,-.5);
         \foreach \i in {0,.1,...,10}
        \draw[line width=.2pt] (\i,-.5)--(\i,-.6);
        \foreach \i in {0.5,1.5,...,9.5}
        \draw[line width=.4pt] (\i,-.5)--(\i,-.7)  node[below] {\tiny $\i$};
            \foreach \i in {0,1,...,10}
                \draw[line width=.8pt] (\i,-.5)--(\i,-.8) node[below] {\footnotesize \bfseries $\i$};
        \node at (5,-1.3) () {\footnotesize cm};
        \draw[line width=.05pt]  (.57,.6)--(.57,-.4)
                    (2.09,.6)--(2.09,-.4)
                    (3.61,.6)--(3.61,-.4)
                    (5.13,.6)--(5.13,-.4)
                    (6.65,.6)--(6.65,-.4)
                    (8.17,.6)--(8.17,-.4)
                    (9.685,.6)--(9.685,-.4)
                    (.57,.6)--(9.685,.6);
       \foreach \i in {1.3,2.82,4.34,5.86,7.38,8.9}
            \node[fill=white] at (\i,.6) () {\tiny $\lambda=1.52$};
    \end{tikzpicture}
\end{document}

输出为:

在此处输入图片描述

您可以在其中注释或删除标尺的代码。

编辑没有统治者

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\mytransformation{%
\pgfmathsetmacro{\myX}{\pgf@x + 2*cos(\pgf@x*8)}
%\pgfmathsetmacro{\myY}{\pgf@y}
\setlength{\pgf@x}{\myX pt}
%\setlength{\pgf@y}{\myY pt}
}
\makeatother
\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \pgftransformnonlinear{\mytransformation}
            \draw[cyan,line width=1pt,decoration={aspect=0.3, segment length=2.5mm, amplitude=4mm,coil},decorate]
                (0,0) -- (10,0);
        \end{scope}
%       \draw (0,-.5) -- (10,-.5);
%        \foreach \i in {0,.1,...,10}
%       \draw[line width=.2pt] (\i,-.5)--(\i,-.6);
%       \foreach \i in {0.5,1.5,...,9.5}
%       \draw[line width=.4pt] (\i,-.5)--(\i,-.7)  node[below] {\tiny $\i$};
%           \foreach \i in {0,1,...,10}
%               \draw[line width=.8pt] (\i,-.5)--(\i,-.8) node[below] {\footnotesize \bfseries $\i$};
%       \node at (5,-1.3) () {\footnotesize cm};
        \draw[line width=.05pt]  (.57,.6)--(.57,.3)
                    (2.09,.6)--(2.09,.3)
                    (3.61,.6)--(3.61,.3)
                    (5.13,.6)--(5.13,.3)
                    (6.65,.6)--(6.65,.3)
                    (8.17,.6)--(8.17,.3)
                    (9.685,.6)--(9.685,.3)
                    (.57,.6)--(9.685,.6);
       \foreach \i in {1.3,2.82,4.34,5.86,7.38,8.9}
            \node[fill=white] at (\i,.6) () {\tiny $\!\lambda{=}1.52\!$};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

...还有一些小变化!

相关内容