应用moospit的答案后:

应用moospit的答案后:

考虑下面的图形: 在此处输入图片描述

是否有可能在 TikZ 中自动构建类似的东西?在过去的一个小时左右,我一直在尝试手动绘图 - 但它很耗时,而且很难完美。

这个想法是“v_AN”是创建列,其中“v_control,A”价值高于“v_tri”. 同样适用于“v_control,B”。最后一个阶段不相关。
我试图通过在上图中放置红线和绿线来解释这一点。

我猜想挑战在于创建一个表格或坐标值,其中控制电压超过三角电压,然后使用这些值来构建实际脉冲。(它们都具有完全相同的高度)

最终图表显示,两组列(v_A0 和 v_B0)相减,形成线电压。(这是我手动绘制的)

应用moospit的答案后:

(抱歉,我不得不把它简化一点,以修复蓝色和红色曲线交叉点的奇数/偶数问题)

\documentclass[tikz, border=6mm]{standalone}

\usetikzlibrary{intersections}

\begin{document}
  \newcommand{\step}{.5}
  \begin{tikzpicture}[>=latex]
    \draw [->] (0,0) -- ++(8,0) node [right] {$t$};
    \draw [->] (0,-1.5) -- ++(0,3) node [midway, left] {$0$};
    \draw [name path=zigzag] 
      \foreach \x in {0,\step,...,6} {
        (\x,0) -- ++(\step/4,-1.5) -- ++(\step/2,3) -- ++(\step/4,-1.5)
      };

%    \foreach \p\l\c in {0/1/red, -0.67*pi/2/blue, 0.67*pi/3/green} 
    
    %RED
      \draw [red,smooth, domain=0:2*pi+.5, name path global=wave-1] plot ({\x},{sin((\x+0) r)}) node [below right, font=\scriptsize] {$sig_1$};
      \draw [red,name intersections={of={wave-1} and zigzag, total=\n}]
        \foreach \i [remember=\i as \lasti (initially 2)] in {1,...,\n} {
          \ifodd\i {}
          \else
            (intersection-\lasti) -- (intersection-\i |- intersection-\lasti)
            (intersection-\lasti |- 0,-2*1) rectangle (intersection-\i |- 0,-3)  
          \fi
        };
      \draw [->] (0,-3) -- ++(8,0) node [right, font=\scriptsize] {$sig_1$};
      \draw [->] (0,-3) node [left] {0} -- ++(0,1.2) node [above] {$v_{1 N}$};      
    
    
    %Blue
     \draw [blue,smooth, domain=0:2*pi+.5, name path global=wave-2] plot ({\x},{sin((\x+-0.67*pi) r)}) node [right, font=\scriptsize] {$sig_2$};
      \draw [blue,name intersections={of={wave-2} and zigzag, total=\n}]
        \foreach \i [remember=\i as \lasti (initially 0.01)] in {1,...,\n} {
          \ifodd\i {}
          \else
            (intersection-\lasti) -- (intersection-\i |- intersection-\lasti)
            (intersection-\lasti |- 0,-2*2) rectangle (intersection-\i |- 0,-5)  
          \fi
        };
      \draw [->] (0,-5) -- ++(8,0) node [right, font=\scriptsize] {$sig_2$};
      \draw [->] (0,-5) node [left] {0} -- ++(0,1.2) node [above] {$v_{2 N}$};      
    
    
      %GREEN
     \draw [green,smooth, domain=0:2*pi+.5, name path global=wave-3] plot ({\x},{sin((\x+0.67*pi) r)}) node [above right, font=\scriptsize] {$sig_3$};
      \draw [green,name intersections={of={wave-3} and zigzag, total=\n}]
        \foreach \i [remember=\i as \lasti (initially 0.5)] in {1,...,\n} {
          \ifodd\i
            (intersection-\lasti) -- (intersection-\i |- intersection-\lasti)
            (intersection-\lasti |- 0,-2*3) rectangle (intersection-\i |- 0,-7)  
          \fi
        };
      \draw [->] (0,-7) -- ++(8,0) node [right, font=\scriptsize] {$sig_3$};
      \draw [->] (0,-7) node [left] {0} -- ++(0,1.2) node [above] {$v_{3 N}$};      
    
    
  \end{tikzpicture}
\end{document}

现在,我“仅”需要实现原始图形中所示的底部曲线。这可能需要一些反复试验 :) 在此处输入图片描述

答案1

这是我之前为类似您的图形使用的一些代码。我尝试将其应用于您的问题,它应该可以解决所有问题,除了您的最后一个图。您也可以尝试使用intersections现有路径创建这个图。

intersection可以通过命令来控制点,以\step实现锯齿形步骤和图的相移,在示例中sin使用倍数。pi

如果您需要使用不同的点,您可以调整循环中的选项和intersection计数器。initiallyrememberforeach

重要的:为了获取所有交点,我建议使用 -optionsmooth或选择绘图的高samples值。在本例中,使用 100 个样本显示不够。

\documentclass[tikz, border=6mm]{standalone}

\usetikzlibrary{intersections}

\begin{document}
  \newcommand{\step}{.5}
  \begin{tikzpicture}[>=latex]
    \draw [->] (0,0) -- ++(8,0) node [right] {$t$};
    \draw [->] (0,-1.5) -- ++(0,3) node [midway, left] {$0$};
    \draw [name path=zigzag] 
      \foreach \x in {0,\step,...,6} {
        (\x,0) -- ++(\step/4,-1.5) -- ++(\step/2,3) -- ++(\step/4,-1.5)
      };

    \foreach \p\l\c in {0/1/red,.5*pi/2/blue,pi/3/green} {
      \draw [\c,smooth, domain=0:2*pi+.5, name path global=wave-\l] plot ({\x},{sin((\x+\p) r)}) node [right, font=\scriptsize] {$sig_\l$};
      \draw [\c,name intersections={of={wave-\l} and zigzag, total=\n}]
        \foreach \i [remember=\i as \lasti (initially 2)] in {3,...,\n} {
          \ifodd\i
            (intersection-\lasti) -- (intersection-\i |- intersection-\lasti)
            (intersection-\lasti |- 0,-2*\l) rectangle (intersection-\i |- 0,-2*\l-1)
          \fi
        };
      \draw [->] (0,-2*\l-1) -- ++(8,0) node [right, font=\scriptsize] {$sig_\l$};
      \draw [->] (0,-2*\l-1) node [left] {0} -- ++(0,1) node [above] {$v_{\l N}$};      
    }
  \end{tikzpicture}
\end{document}

渲染图像

更新:

这是完成整个过程的方法。我使用你的sig1sig2(一次填充红色/蓝色,一次填充白色)的副本并将它们重叠。

重要的:根据您为第一个图选择的值,-wave的位置sin需要手动计算(我只是做了近似值)。

我重用了您提供的代码,并添加了我自己的内容。此版本可能需要一些清理,但它可以正常工作。

\documentclass[tikz, border=6mm]{standalone}

\usetikzlibrary{calc, intersections}

\begin{document}
\newcommand{\step}{.5}
\begin{tikzpicture}[>=latex]
  \draw [->] (0,0) -- ++(8,0) node [right] {$t$};
  \draw [->] (0,-1.5) -- ++(0,3) node [midway, left] {$0$};
  \draw [name path=zigzag] 
  \foreach \x in {0,\step,...,6} {
    (\x,0) -- ++(\step/4,-1.5) -- ++(\step/2,3) -- ++(\step/4,-1.5)
  };

  %RED
  \draw [red,smooth, domain=0:2*pi+.5, name path global=wave-1] plot ({\x},{sin((\x+0) r)}) node [below right, font=\scriptsize] {$sig_1$};
  \fill [red,name intersections={of={wave-1} and zigzag, total=\n}]
    \foreach \i [remember=\i as \lasti (initially 2)] in {1,...,\n} {
      \ifodd\i {}
      \else
        (intersection-\lasti |- 0,-2) rectangle (intersection-\i |- 0,-3)
        (intersection-\lasti |- 0,-6) rectangle (intersection-\i |- 0,-7)  
      \fi
    };
  \draw [->] (0,-3) -- ++(8,0) node [right, font=\scriptsize] {$sig_1$};
  \draw [->] (0,-3) node [left] {0} -- ++(0,1.2) node [above] {$v_{1 N}$};      


  %Blue
  \draw [blue, smooth, domain=0:2*pi+.5, name path global=wave-2] plot ({\x},{sin((\x+-0.67*pi) r)}) node [right, font=\scriptsize] {$sig_2$};
  \fill [blue,name intersections={of={wave-2} and zigzag, total=\n}]
    \foreach \i [remember=\i as \lasti (initially 0.01)] in {1,...,\n} {
      \ifodd\i {}
      \else
        (intersection-\lasti |- 0,-4) rectangle (intersection-\i |- 0,-5)
                    (intersection-\lasti |- 0,-7) rectangle (intersection-\i |- 0,-8)
      \fi
    };
  \draw [->] (0,-5) -- ++(8,0) node [right, font=\scriptsize] {$sig_2$};
  \draw [->] (0,-5) node [left] {0} -- ++(0,1.2) node [above] {$v_{2 N}$};      


    % Last plot    
    \fill [white,name intersections={of={wave-1} and zigzag, total=\n}]
      \foreach \i [remember=\i as \lasti (initially 2)] in {1,...,\n} {
        \ifodd\i {}
        \else
                    ($(intersection-\lasti |- 0,-7)$) rectangle ($(intersection-\i |- 0,-8)+(0,-.1)$)
       \fi
       };

     \fill [white,name intersections={of={wave-2} and zigzag, total=\n}]
    \foreach \i [remember=\i as \lasti (initially 0.01)] in {1,...,\n} {
      \ifodd\i {}
      \else     
        ($(intersection-\lasti |- 0,-6)+(0,.1)$) rectangle ($(intersection-\i |- 0,-7)$)
         \fi
            };

    \draw [smooth, domain=0:2*pi+.5] plot ({\x},{-7+sin((\x+.165*pi) r)});

    \draw [->] (0,-8.5) -- ++(0,3) node [midway, left] {$0$};
    \draw [->] (0,-7) -- ++(8,0) node [right] {$t$};


  \end{tikzpicture}
\end{document}

渲染图像

相关内容