원추형 및 원통형 나선

Nov 25 2020

Ti k Z 에서 다음과 같은 것을 그리고 싶지만, 불행히도 필요한 결과를 얻는 방법을 잘 모르겠습니다. 이 그림은 사중 극자 질량 분석기의 이온 경로를 보여줍니다. 사중 극자 (4 개의 막대) 외부에서는 전자기장이 이온에 적용되지 않으므로 이온은 직선으로 비행합니다. 그들이 사중 극 자로 들어가면 전자기장과 공명하여 원통형 나선형 경로에 있거나 공진하지 않아 원추형 나선형 경로에 있고 조만간 측면에서 사중 극자를 빠져 나갈 수 있습니다.

이 문제에 대한 필자 는 원추형 플롯과 원통형 pgfplots플롯에 대한 기능이있는 3D 플롯을 사용하여 나선을 그리는 데 사용했습니다 . 안타깝게도 다음 문제를 해결할 수 없습니다.{x*cos(deg(x))},{x*sin(deg(x)},{x}{cos(deg(x))},{sin(deg(x)},{x}

  • 나선을 올바르게 배치
  • 나선형으로 변형 된 직선을 그리고 사중 극자를 빠져 나간 후 다시 직선으로 돌아갑니다 (원통형에만 해당)
  • 경로가 사중 극자에서 나간 직후 원뿔형 나선을 중지합니다.

나는 이것이 상당히 많은 문제라는 것을 잘 알고 있으므로 어떤 힌트에도 만족합니다.

나의 현재 (비참한) 시도

\documentclass{standalone}

\usepackage{xparse}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}
    % General constants
    % %%%%%%%%%%%%%%%%%

    \coordinate (msOrigin) at (0,0);
    \pgfmathsetmacro{\msY}{3}

    \pgfmathsetmacro{\offsetX}{0.3}
    \pgfmathsetmacro{\offsetY}{0.2}
    \pgfmathsetmacro{\spacer}{0.75}
    \pgfmathsetmacro{\arrowLength}{1}
    \pgfmathsetmacro{\centerOffset}{0.3}


    % Quadrupole constants
    % %%%%%%%%%%%%%%%%%%%%

    \pgfmathsetmacro{\quadrupoleRadiusHorizontal}{0.08}
    \pgfmathsetmacro{\quadrupoleRadiusVertical}{0.2}
    \pgfmathsetmacro{\quadrupoleLength}{3}
    \pgfmathsetmacro{\quadrupolePathLength}{\quadrupoleLength - (2 * \quadrupoleRadiusHorizontal)}

    \pgfmathsetmacro{\quadrupoleTopFrontY}{0.5 * \msY + \centerOffset + 2 * \quadrupoleRadiusVertical}
    \pgfmathsetmacro{\quadrupoleTopBackY}{\quadrupoleTopFrontY + \offsetY}
    \pgfmathsetmacro{\quadrupoleBottomBackY}{0.5 * \msY - \centerOffset}
    \pgfmathsetmacro{\quadrupoleBottomFrontY}{\quadrupoleBottomBackY - \offsetY}
    
    \NewDocumentCommand{\cylinder}{m m m m m m m m}{%  coordX, coordY, length, radiusX, radiusY, colorCylinder, colorEllipse, opacity
        \fill [#6, fill opacity = #8]
            ($ (msOrigin) + ({#1},{#2}) $)
            --
            ++({#3},0)
            arc
            (90:270:-{#4} and {#5})
            --
            ++(-{#3},0)
            arc
            (270:90:-{#4} and {#5});

        \draw [fill = #7, fill opacity = #8]
            ($ (msOrigin) + ({#1},{#2}) + (0,{-#5}) $)
            ellipse
            ({#4} and {#5});

        \draw
            ($ (msOrigin) + ({#1},{#2}) $)
            --
            ++({#3},0)
            arc
            (90:270:-{#4} and {#5})
            --
            ++(-{#3},0);
    }

    \NewDocumentCommand{\quadrupoleRod}{m m m}{% segment, top/bottom, front/back
        \ifthenelse{\equal{#2}{top} \AND \equal{#3}{front}}{%
            \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal + \offsetX}
            \pgfmathsetmacro{\coordY}{\quadrupoleTopFrontY}
        }{}

        \ifthenelse{\equal{#2}{top} \AND \equal{#3}{back}}{%
            \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal}
            \pgfmathsetmacro{\coordY}{\quadrupoleTopBackY}
        }{}

        \ifthenelse{\equal{#2}{bottom} \AND \equal{#3}{front}}{%
            \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal + \offsetX}
            \pgfmathsetmacro{\coordY}{\quadrupoleBottomFrontY}
        }{}

        \ifthenelse{\equal{#2}{bottom} \AND \equal{#3}{back}}{%
            \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal}
            \pgfmathsetmacro{\coordY}{\quadrupoleBottomBackY}
        }{}

        \cylinder
            {\coordX}
            {\coordY}
            {\quadrupolePathLength}
            {\quadrupoleRadiusHorizontal}
            {\quadrupoleRadiusVertical}
            {gray}
            {white}
            {1}
    }

    \NewDocumentCommand{\quadrupolePair}{m m}{% segment, front/back
        \ifthenelse{\equal{#2}{front} \OR \equal{#2}{back}}{%
            \quadrupoleRod{#1}{top}{#2}
            \quadrupoleRod{#1}{bottom}{#2}
        }{}
    }
    
    \quadrupolePair{1}{back}
    \begin{axis}[
        rotate around={-90:(current axis.origin)},
        view = {30}{20},
        axis line style = {draw = none},
        tick style = {draw = none},
        zmax = 60,
        xtick=\empty,
        ytick=\empty,
        ztick=\empty
    ]
        \addplot3+[
            mark = none,
            thick,
            red,
            domain = 0:50*pi,
            samples = 1000,
            samples y = 0,
        ]
        % ({x*cos(deg(x))},{x*sin(deg(x)},{x});
        ({cos(deg(x))},{sin(deg(x)},{x});
    \end{axis}
    \quadrupolePair{1}{front}
\end{tikzpicture}

\end{document}

업데이트 2020-11-26

TeX.SX 에서이 답변이 원통형 코일을 그리는 데 도움 이 되는 것을 발견 했습니다 . 약간의 수정으로 나는 그 과정에서 상대적으로 멀리 갈 수 있었다. 남은 문제 중 하나는 코드 mark=at position #1 with \coordinate (#2);Dimension too large.오류를 던질 때 수평 경로를 나선형으로 연결하는 선 입니다. 이유를 이해하지 못하더라도. 코일은 작고 확실히 19 피트 미만입니다 ...

남아있는 또 다른 문제는 원추형 나선형입니다. 출발점이 있지만 안타깝게도 끔찍해 보입니다.

\documentclass{standalone}

\usepackage{xparse}
\usepackage{ifthen}
\usepackage{tikz}

\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}

\tikzset{
    mark position/.style args={#1(#2)}{
        postaction={
            decorate,
            decoration={
                markings,
                mark=at position #1 with \coordinate (#2);
            }
        }
    }
}

\NewDocumentCommand{\cylinder}{m m m m m m m m}{%  coordX, coordY, length, radiusX, radiusY, colorCylinder, colorEllipse, opacity
    \fill [#6, fill opacity = #8]
        ($ (msOrigin) + ({#1},{#2}) $)
        --
        ++({#3},0)
        arc
        (90:270:-{#4} and {#5})
        --
        ++(-{#3},0)
        arc
        (270:90:-{#4} and {#5});

    \draw [fill = #7, fill opacity = #8]
        ($ (msOrigin) + ({#1},{#2}) + (0,{-#5}) $)
        ellipse
        ({#4} and {#5});

    \draw
        ($ (msOrigin) + ({#1},{#2}) $)
        --
        ++({#3},0)
        arc
        (90:270:-{#4} and {#5})
        --
        ++(-{#3},0);
}

\NewDocumentCommand{\quadrupoleRod}{m m m}{% segment, top/bottom, front/back
    \ifthenelse{\equal{#2}{top} \AND \equal{#3}{front}}{%
        \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal + \offsetX}
        \pgfmathsetmacro{\coordY}{\quadrupoleTopFrontY}
    }{}

    \ifthenelse{\equal{#2}{top} \AND \equal{#3}{back}}{%
        \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal}
        \pgfmathsetmacro{\coordY}{\quadrupoleTopBackY}
    }{}

    \ifthenelse{\equal{#2}{bottom} \AND \equal{#3}{front}}{%
        \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal + \offsetX}
        \pgfmathsetmacro{\coordY}{\quadrupoleBottomFrontY}
    }{}

    \ifthenelse{\equal{#2}{bottom} \AND \equal{#3}{back}}{%
        \pgfmathsetmacro{\coordX}{\quadrupoleRadiusHorizontal}
        \pgfmathsetmacro{\coordY}{\quadrupoleBottomBackY}
    }{}

    \cylinder
        {\coordX}
        {\coordY}
        {\quadrupolePathLength}
        {\quadrupoleRadiusHorizontal}
        {\quadrupoleRadiusVertical}
        {gray}
        {white}
        {1}
}

\NewDocumentCommand{\quadrupolePair}{m m}{% segment, front/back
    \ifthenelse{\equal{#2}{front} \OR \equal{#2}{back}}{%
        \quadrupoleRod{#1}{top}{#2}
        \quadrupoleRod{#1}{bottom}{#2}
    }{}
}

\begin{document}

% General constants
% %%%%%%%%%%%%%%%%%
\pgfmathsetmacro{\offsetX}{0.5}
\pgfmathsetmacro{\offsetY}{0.6}
\pgfmathsetmacro{\spacer}{0.75}
\pgfmathsetmacro{\centerOffset}{0.3}


% Quadrupole constants
% %%%%%%%%%%%%%%%%%%%%

\pgfmathsetmacro{\quadrupoleRadiusHorizontal}{0.08}
\pgfmathsetmacro{\quadrupoleRadiusVertical}{0.2}
\pgfmathsetmacro{\quadrupoleLength}{4}
\pgfmathsetmacro{\quadrupolePathLength}{\quadrupoleLength - (2 * \quadrupoleRadiusHorizontal)}

\pgfmathsetmacro{\quadrupoleTopFrontY}{\centerOffset + 2 * \quadrupoleRadiusVertical}
\pgfmathsetmacro{\quadrupoleTopBackY}{\quadrupoleTopFrontY + \offsetY}
\pgfmathsetmacro{\quadrupoleBottomBackY}{-\centerOffset}
\pgfmathsetmacro{\quadrupoleBottomFrontY}{\quadrupoleBottomBackY - \offsetY}

\begin{tikzpicture}
    \coordinate (msOrigin) at (0,0);
    
    % Define a formula for the coil.
    % This is what the numbers mean:
    % 0.25: the x offset
    % 0.13: how far the rings are apart
    % 0.30: how much from the side the rings are seen
    % 0.75: radius of the rings
    \def\coil#1{
        {0.25 + 0.13 * (2 * #1 + \t) + 0.30 * sin(- \t  *  pi r))},
        {0.75 * cos(-\t * pi r)}
    }

    % Draw the background-rods
    \quadrupolePair{1}{back}
    
    % Draw the part of the coil behind
    \foreach \n in {1,...,14} {
        \draw[domain={0:1},smooth,variable=\t,samples=15]
            plot (\coil{\n}); 
    }

    % Draw the part of the coil in front
    \foreach \n in {0,1,...,13} {
        \ifthenelse{\equal{\n}{0} \OR \equal{\n}{13}}
        {%
            \ifthenelse{\equal{\n}{0}}{%
                \draw[
                    domain = {1:2},
                    smooth,
                    variable = \t,
                    samples = 15,
                    % mark position = 0(start)
                ]
                    plot (\coil{\n});
            }{%
            \draw[
                    domain = {1:2},
                    smooth,
                    variable = \t,
                    samples = 15,
                    % mark position = 1(end)
                ]
                    plot (\coil{\n});
            }
        }{
            \draw[
                domain = {1:2},
                smooth,
                variable = \t,
                samples = 15
            ]
                plot (\coil{\n});
        }
    }
    
    % Draw the foreground-rods
    \quadrupolePair{1}{front}
    
    \draw 
        % (start) % to join the mark position "start"
        (0.25, -0.75)
        to [out = 180, in = 0] 
        ++(-1, 0.75);
    \draw 
        % (end) % to join the mark position "end"
        (4, -0.75) 
        to [out = 0, in = 180] 
        ++(1, 0.75);
\end{tikzpicture}

\hspace{1em}

\begin{tikzpicture}
    \coordinate (msOrigin) at (0,0);
    
    % Define a formula for the coil.
    % This is what the numbers mean:
    % 0.25: the x offset
    % 0.13: how far the rings are apart
    % 0.30: how much from the side the rings are seen
    % 0.75: radius of the rings
    \def\coil#1{
        {0.25 + 0.13 * (2 * #1 + \t) + 0.30 * sin(- \t  *  pi r)},
        {0.75 * #1/10 * \t * cos(-\t * pi r)}
    }

    % Draw the background-rods
    \quadrupolePair{1}{back}
    
    % Draw the part of the coil behind
    \foreach \n in {1,...,14} {
        \draw[domain={0:1},smooth,variable=\t,samples=15]
            plot (\coil{\n});
    }

    % Draw the part of the coil in front
    \foreach \n in {0,1,...,13} {
        \ifthenelse{\equal{\n}{0} \OR \equal{\n}{13}}
        {%
            \ifthenelse{\equal{\n}{0}}{%
                \draw[
                    domain = {1:2},
                    smooth,
                    variable = \t,
                    samples = 15,
                    % mark position = 0(start)
                ]
                    plot (\coil{\n});
            }{%
            \draw[
                    domain = {1:2},
                    smooth,
                    variable = \t,
                    samples = 15,
                    % mark position = 1(end)
                ]
                    plot (\coil{\n});
            }
        }{
            \draw[
                domain = {1:2},
                smooth,
                variable = \t,
                samples = 15
            ]
                plot (\coil{\n});
        }
    }
    
    % Draw the foreground-rods
    \quadrupolePair{1}{front}

\end{tikzpicture}

\end{document}

답변

3 hpekristiansen Nov 26 2020 at 23:08

나는 PGF 코드를 사용할 이유가 없다고 생각합니다. 나선이 {cos(deg(x))},{sin(deg(x)},{x}. 나는 일반적으로 PGFPlots를 좋아하지만 이것은 플롯 (축, 스케일, 눈금, 레이블, ...)이 아닙니다. 나는 plotTikZ 의 기능이 올바른 방법 이라고 믿습니다 .

나선형의 끝을 곧게 펴기 위해 루프의 피치와 동일하게 진폭을 감소시킵니다. 원뿔형이 어떻게 끝나기를 원하는지 잘 모르겠습니다. 간단한 방법은 코일의 진폭을 빠르게 올리고 도메인을 조정하는 것입니다.

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[ultra thick]
\newcommand{\domA}{-pi}
\newcommand{\domB}{0}
\newcommand{\domC}{2*pi}
\newcommand{\domD}{4*pi}
\newcommand{\domE}{\domC+0.5}
\newcommand{\pitch}{10}
\newcommand{\ampA}{(1/(1+\domB-\x))}
\newcommand{\ampB}{(1/(1-\domC+\x))}
\newcommand{\ampC}{(0.1*(\x-\domB)+1)}

\draw[red, domain={\domA:\domB}, smooth, samples=100] plot (\x, {\ampA*cos((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}, {\ampA*sin((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}  );
\draw[green, domain={\domB:\domC}, smooth, samples=200] plot (\x, {cos(\pitch*\x r)} , {sin(\pitch*\x r)} );
\draw[blue, domain={\domC:\domD}, smooth, samples=100] plot (\x, {\ampB*cos((\ampB*\pitch*\x+(1-\ampB)*\pitch*\domC) r)}, {\ampB*sin((\ampB*\pitch*\x+(1-\ampB)*\pitch*\domC) r)}  );

\begin{scope}[yshift=-4cm]
\draw[teal, domain={\domA:\domB}, smooth, samples=100] plot (\x, {cos((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}, {sin((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}  );
\draw[orange, domain={\domB:\domC}, smooth, samples=200] plot (\x, {\ampC*cos(\pitch*\x r)} , {\ampC*sin(\pitch*\x r)} );
\draw[violet, domain={\domC:\domE}, smooth, samples=100] plot (\x, {\ampC*1/\ampB*cos(\pitch*\x r)} , {\ampC*1/\ampB*sin(\pitch*\x r)} );
\end{scope}

\end{tikzpicture}
\end{document}

편집하다:

TikZ의 기본 z- 벡터는 (−3.85mm, −3.85mm)를 가리 킵니다. 관점을 변경하려면 다음 z={(-3.85mm, 3.85mm)}과 같이 사용할 수 있습니다 .

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}[z={(-3.85mm, 3.85mm)}]
\newcommand{\domA}{-pi}
\newcommand{\domB}{0}
\newcommand{\domC}{2*pi}
\newcommand{\domD}{4*pi}
\newcommand{\domE}{\domC+0.5}
\newcommand{\pitch}{10}
\newcommand{\ampA}{(1/(1+\domB-\x))}
\newcommand{\ampB}{(1/(1-\domC+\x))}
\newcommand{\ampC}{(0.1*(\x-\domB)+1)}

\draw[fill=gray] (-1,1.2,1) -- (7,1.2,1) arc[start angle=90, end angle=-90, x radius=0.1cm, y radius=0.2cm] -- (-1,0.8,1);
\draw[fill=white](-1,1,1) circle[x radius=0.1cm, y radius=0.2cm];
\draw[fill=gray] (-1,-1.2,1) -- (7,-1.2,1) arc[start angle=-90, end angle=90, x radius=0.1cm, y radius=0.2cm] -- (-1,-0.8,1);
\draw[fill=white](-1,-1,1) circle[x radius=0.1cm, y radius=0.2cm];

\draw[red, thick, domain={\domA:\domB}, smooth, samples=100] plot (\x, {\ampA*cos((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}, {\ampA*sin((\ampA*\pitch*\x+(1-\ampA)*\pitch*\domB) r)}  );
\draw[red, thick, domain={\domB:\domC}, smooth, samples=200] plot (\x, {cos(\pitch*\x r)} , {sin(\pitch*\x r)} );
\draw[red, thick, domain={\domC:\domD}, smooth, samples=100] plot (\x, {\ampB*cos((\ampB*\pitch*\x+(1-\ampB)*\pitch*\domC) r)}, {\ampB*sin((\ampB*\pitch*\x+(1-\ampB)*\pitch*\domC) r)}  );

\draw[fill=gray] (-1,1.2,-1) -- (7,1.2,-1) arc[start angle=90, end angle=-90, x radius=0.1cm, y radius=0.2cm] -- (-1,0.8,-1);
\draw[fill=white](-1,1,-1) circle[x radius=0.1cm, y radius=0.2cm];
\draw[fill=gray] (-1,-1.2,-1) -- (7,-1.2,-1) arc[start angle=-90, end angle=90, x radius=0.1cm, y radius=0.2cm] -- (-1,-0.8,-1);
\draw[fill=white](-1,-1,-1) circle[x radius=0.1cm, y radius=0.2cm];

\end{tikzpicture}
\end{document}

빨간색 나선형의 꼬임은 smooth다른 플롯에서 작동하지 않기 때문 입니다. 이를 수정하는 두 가지 방법을 볼 수 있습니다. smooth옵션을 제거 하고 샘플을 많이 늘립니다. -또는 그 이상 : TikZ declare function를 사용 하여 조각 별 함수를 선언하고 하나의 플롯 만 수행 합니다.