电机电路的横截面

电机电路的横截面

我正在尝试绘制下图tikz

在此处输入图片描述

我编写了以下代码,重新生成的图形如下:

\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{rotating}


\begin{document}
\begin{tikzpicture}[line width=0.5mm]

    \draw (0,0) circle (3cm);

    \begin{rotate}{60}

        \draw (-1.475,0) -- (1.475,0);
        \draw (-1.87,0) -- (-4,0);
        \draw[->, >=stealth] (1.87,0) -- (4,0) node[anchor= south, style={rotate=-60}] {$\boldsymbol{\gamma}$};
        \draw (0,-1.475) -- (0,1.475);
        \draw (0,-1.87) -- (0,-4);
        \draw[->, >=stealth] (0,1.87) -- (0,4) node[anchor= east, style={rotate=-60}] {$\boldsymbol{\delta}$};

        \draw (1.75,0.15) arc (5:85:1.76);
        \draw (-0.15,1.75) arc (95:175:1.76);
        \draw (-1.75,-0.15) arc (185:265:1.76);
        \draw (0.15,-1.75) arc (275:355:1.76);

        \draw (1.775, -0.15) -- (1.475,-0.15) -- (1.475,0.15) -- (1.775,0.15) node[anchor= north,xshift=-0.2cm,yshift=0.3cm,style={rotate=-60}] {$\boldsymbol{i_{r\delta}}$};
        \draw (-0.15,1.775) -- (-0.15,1.475) -- (0.15,1.475) -- (0.15,1.775) node[anchor= south,xshift=0cm,yshift=-0.6cm,style={rotate=-60}] {$\boldsymbol{i_{r\gamma}}$};
        \draw (-1.775, 0.15) -- (-1.475,0.15) -- (-1.475,-0.15) -- (-1.775,-0.15);
        \draw (0.15,-1.775) -- (0.15,-1.475) -- (-0.15,-1.475) -- (-0.15,-1.775);

        \draw[blue] (1.64,0) node {$\otimes$};
        \draw[blue] (-1.64,0) node {$\odot$};
        \draw[red] (0,1.64) node {$\odot$};
        \draw[red] (0,-1.64) node {$\otimes$};

    \end{rotate}

    \draw (-1.75,0) -- (1.75,0);
    \draw (-2.125,0) -- (-4,0);
    \draw[->, >=stealth] (2.125,0) -- (4,0) node[anchor= west] {$\boldsymbol{\alpha}$};
    \draw (0,-1.75) -- (0,1.75);
    \draw (0,-2.125) -- (0,-4);
    \draw[->, >=stealth] (0,2.125) -- (0,4) node[anchor= south] {$\boldsymbol{\beta}$};

    \draw (1.85,0.15) arc (5:85:1.87);
    \draw (-0.15,1.85) arc (95:175:1.87);
    \draw (-1.85,-0.15) arc (185:265:1.87);
    \draw (0.15,-1.85) arc (275:355:1.87);

    \draw (1.825, -0.15) -- (2.125,-0.15) -- (2.125,0.15) -- (1.825,0.15) node[anchor= west,xshift=0.2cm,yshift=0.1cm] {$\boldsymbol{i_{s\beta}}$};
    \draw (-0.15,1.825) -- (-0.15,2.125) -- (0.15,2.125) -- (0.15,1.825) node[anchor= south,xshift=0.3cm,yshift=0.1cm] {$\boldsymbol{i_{s\alpha}}$};
    \draw (-1.825, 0.15) -- (-2.125,0.15) -- (-2.125,-0.15) -- (-1.825,-0.15);
    \draw (0.15,-1.825) -- (0.15,-2.125) -- (-0.15,-2.125) -- (-0.15,-1.825);

    \draw[blue] (1.96,0) node {$\otimes$};
    \draw[blue] (-1.96,0) node {$\odot$};
    \draw[red] (0,1.96) node {$\odot$};
    \draw[red] (0,-1.96) node {$\otimes$};



    \draw[->, >=stealth] (0.5,0) arc (0:60:0.5) node[pos=0.5 ,anchor= west] {$\boldsymbol{\varepsilon_{rs}}$};



\end{tikzpicture}

\end{document}

在此处输入图片描述

结果看起来不错。我想知道有没有更好更简单的方法来编写代码?

答案1

calc只是为了好玩,使用、、和的arrows.meta选项,使用节点坐标绘制切割形状,并且只对半径和节点框的角度进行一次计算。然后使用将标签放入图案内,用于我使用的数学字体。backgroundspatternscontourmathptmx

结果:

在此处输入图片描述

梅威瑟:

\documentclass[tikz,border=20pt]{standalone}
\usepackage{mathptmx}
\usepackage[outline]{contour}
\usetikzlibrary{calc,arrows.meta,patterns,backgrounds}

\contourlength{1.1pt}
%Create a new patern for firefox and adobe reader from https://tex.stackexchange.com/a/219808/154390
\pgfdeclarepatternformonly{north east lines b}{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{3.4pt}{3.4pt}}{\pgfqpoint{3.4pt}{3.4pt}}%
{
  \pgfsetlinewidth{0.25pt}
  %Principal line
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{3.4pt}{3.4pt}}
  %Complement line north east
  \pgfpathmoveto{\pgfqpoint{-1pt}{2.4pt}}
  \pgfpathlineto{\pgfqpoint{1pt}{4.4pt}}
  %Complement line south west
  \pgfpathmoveto{\pgfqpoint{2.4pt}{-1pt}}
  \pgfpathlineto{\pgfqpoint{4.4pt}{1pt}}
  \pgfusepath{stroke}
}

\begin{document}
    \begin{tikzpicture}[
        >={Stealth[inset=0,length=5pt]}
    ]
    \def\Current[#1][#2](#3)(#4)#5#6[#7]%1: Angle 2: radious 3:type 4:ID 5:color 6:Label text 7:polar text position.
        \draw (#1:#2)++(#7:0.5) node {\contour{white}{#6}};
        \begin{scope}[shift={(#1:#2)}, rotate=#1-90,transform shape]
            \node[inner sep=0,minimum size=13pt](I#4) at (0,0){};
            \ifnum#3=0 \draw[#5,thick](45:5pt) -- (-135:5pt) (-45:5pt) -- (135:5pt) (0,0) circle (5pt); \fi
            \ifnum#3=1 \draw[#5,thick](0,0) circle (5pt);\fill[#5](0,0) circle (2pt); \fi       
        \end{scope}
    }

    %Drawing Stator?
    \Current[0][2](0)(1){blue}{$i_{s\beta}$}[-90]
    \Current[90][2](1)(2){red}{$i_{s\alpha}$}[10]
    \Current[180][2](1)(3){blue}{$i_{s\beta}$}[100]
    \Current[270][2](0)(4){red}{$i_{s\alpha}$}[0]

    \begin{scope}[on background layer]
    \draw[thick,even odd rule,pattern=north east lines b,pattern color=blue]
        let \p1 = (I1.south west),
            \n1 = {veclen(\x1,\y1)},
            \n2 = {atan2(\y1,\x1)}
        in  (\n2:\n1) 
                arc (\n2:90-\n2:\n1) -- (I2.north east) -| (I2.south west) 
                arc (90+\n2:180-\n2:\n1) -- (I3.north east) |- (I3.south west)
                arc (180+\n2:270-\n2:\n1) -- (I4.north east) -| (I4.south west)
                arc (270+\n2:360-\n2:\n1) -- (I1.north east) |- (I1.south west)
        (0,0) circle (3);
    \draw[->,thick](I2.north) -- ++ (0,1.5) node[anchor=45]{$\beta$};
    \draw[->,thick](I1.north) -- ++ (1.5,0) node[anchor=45]{$\alpha$};
    \draw[thick]
        (I1.south) -- (I3.south)
        (I3.north) -- ++ (-1.5,0)
        (I2.south) -- (I4.south)
        (I4.north) -- ++ (0,-1.5);
    \end{scope}

    %Drawing Rotor?
    \contourlength{0pt}
    \begin{scope}[rotate=60]
    \Current[0][1.4](0)(5){blue}{$i_{r\delta}$}[100]
    \Current[90][1.4](1)(6){red}{$i_{r\gamma}$}[-20]
    \Current[180][1.4](1)(7){blue}{$i_{r\delta}$}[70]
    \Current[270][1.4](0)(8){red}{$i_{r\gamma}$}[160]
        \begin{scope}[on background layer]
            \draw[thick,fill=black, fill opacity=0.2]
                let \p1 = (I5.north west),
                    \n1 = {veclen(\x1,\y1)},
                    \n2 = {atan2(\y1,\x1)}
                in  (\n2:\n1) 
                        arc (\n2:90-\n2:\n1) -- (I6.south east) -| (I6.north west) 
                        arc (90+\n2:180-\n2:\n1) -- (I7.south east) |- (I7.north west)
                        arc (180+\n2:270-\n2:\n1) -- (I8.south east) -| (I8.north west)
                        arc (270+\n2:360-\n2:\n1) -- (I5.south east) |- (I5.north west);
            \draw[->,thick, shorten >=10pt](I6.north) -- ++ (0,2.4) node{$\delta$};
            \draw[->,thick, shorten >=10pt](I5.north) -- ++ (2.4,0) node{$\gamma$};
            \draw[thick]
                (I5.south) -- (I7.south)
                (I7.north) -- ++ (-2,0)
                (I6.south) -- (I8.south)
                (I8.north) -- ++ (0,-2);
        \end{scope}
    \end{scope}
    \draw[->,thick] (0:0.7) arc (0:60:0.7) node[pos=0.5 ,anchor= west] {$\varepsilon_{rs}$};
    \end{tikzpicture}
\end{document}

动画片:

避免使用模式,因为在 gif 压缩中会产生不良输出,因此轮廓不是必需的......

结果:

在此处输入图片描述

MWE:foreach 循环出现错误,但在非停止模式下生成必要的帧,然后我使用 Imagemagick 转换器将 pdf 输出转换为 gif。

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 150, delay: 15 , other: -background white -alpha remove}
% arara: showanimate
\documentclass[tikz,border=0pt]{standalone}
\usepackage{mathptmx}
\usetikzlibrary{calc,arrows.meta,backgrounds}

\begin{document}
    \foreach \z in {1,2,...,30}{

    \begin{tikzpicture}[
    >={Stealth[inset=0,length=5pt]}
    ]
    \pgfmathparse{int(\z*360/30)}
    \edef\Rotate{\pgfmathresult}
    \path(0,0) circle (4.5cm);
    \def\Current[#1][#2](#3)(#4)#5#6[#7]{%1: Angle 2: radious 3:type 4:ID 5:color 6:Label text 7:polar text position.
        \draw (#1:#2)++(#7:0.5) node {#6};
        \begin{scope}[shift={(#1:#2)}, rotate=#1-90,transform shape]
        \node[inner sep=0,minimum size=13pt](I#4) at (0,0){};
        \ifnum#3=0 
            \draw[#5,fill=white,thick](0,0) circle (5pt);
            \draw[#5,thick](45:5pt) -- (-135:5pt) (-45:5pt) -- (135:5pt); 
        \fi
        \ifnum#3=1 
            \draw[#5,fill=white,thick](0,0) circle (5pt);\fill[#5](0,0) circle (2pt); \fi       
        \end{scope}
    }

    %Drawing Stator?
    \Current[0][2](0)(1){blue}{$i_{s\beta}$}[-90]
    \Current[90][2](1)(2){red}{$i_{s\alpha}$}[10]
    \Current[180][2](1)(3){blue}{$i_{s\beta}$}[100]
    \Current[270][2](0)(4){red}{$i_{s\alpha}$}[0]

    \begin{scope}[on background layer]
    \draw[thick,even odd rule,fill=blue!20]
    let \p1 = (I1.south west),
    \n1 = {veclen(\x1,\y1)},
    \n2 = {atan2(\y1,\x1)}
    in  (\n2:\n1) 
    arc (\n2:90-\n2:\n1) -- (I2.north east) -| (I2.south west) 
    arc (90+\n2:180-\n2:\n1) -- (I3.north east) |- (I3.south west)
    arc (180+\n2:270-\n2:\n1) -- (I4.north east) -| (I4.south west)
    arc (270+\n2:360-\n2:\n1) -- (I1.north east) |- (I1.south west)
    (0,0) circle (3);
    \draw[->,thick](I2.north) -- ++ (0,1.5) node[anchor=45]{$\beta$};
    \draw[->,thick](I1.north) -- ++ (1.5,0) node[anchor=45]{$\alpha$};
    \draw[thick]
    (I1.south) -- (I3.south)
    (I3.north) -- ++ (-1.5,0)
    (I2.south) -- (I4.south)
    (I4.north) -- ++ (0,-1.5);
    \end{scope}

    %Drawing Rotor?
    \begin{scope}[rotate=\Rotate]
    \Current[0][1.4](0)(5){blue}{$i_{r\delta}$}[100]
    \Current[90][1.4](1)(6){red}{$i_{r\gamma}$}[-20]
    \Current[180][1.4](1)(7){blue}{$i_{r\delta}$}[70]
    \Current[270][1.4](0)(8){red}{$i_{r\gamma}$}[160]
    \begin{scope}[on background layer]
    \draw[thick,fill=black, fill opacity=0.2]
    let \p1 = (I5.north west),
    \n1 = {veclen(\x1,\y1)},
    \n2 = {atan2(\y1,\x1)}
    in  (\n2:\n1) 
    arc (\n2:90-\n2:\n1) -- (I6.south east) -| (I6.north west) 
    arc (90+\n2:180-\n2:\n1) -- (I7.south east) |- (I7.north west)
    arc (180+\n2:270-\n2:\n1) -- (I8.south east) -| (I8.north west)
    arc (270+\n2:360-\n2:\n1) -- (I5.south east) |- (I5.north west);
    \draw[->,thick, shorten >=10pt](I6.north) -- ++ (0,2.4) node{$\delta$};
    \draw[->,thick, shorten >=10pt](I5.north) -- ++ (2.4,0) node{$\gamma$};
    \draw[thick]
    (I5.south) -- (I7.south)
    (I7.north) -- ++ (-2,0)
    (I6.south) -- (I8.south)
    (I8.north) -- ++ (0,-2);
    \end{scope}
    \end{scope}
    \draw[->,thick]
        (0:0.7) arc (0:\Rotate:0.7);
    \draw(\Rotate-15:1) node{$\varepsilon_{rs}$};
    \end{tikzpicture}%
}
\end{document}

相关内容