使用 tikz 的相量

使用 tikz 的相量

r*exp(i \theta)今天下午我正在寻找一种用 tikz 绘制相量的方法(您知道在复平面上表示为或简单的事物x + iy

对我来说,第一种表述更容易处理。

我应该简单地使用极坐标系统吗?但是进行矢量求和会变得很棘手...

答案1

如果你只使用常规极坐标形式,求和并不那么棘手。这是一个简单的入门步骤:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[>=latex]
\draw[style=help lines] (0,0) grid[step=1cm] (3,2);

\coordinate (vec1) at (60:1); % Define some complex numbers
\coordinate (vec2) at (20:2); % with r*exp(i \theta) form

\draw[->,thick,blue] (0,0) -- (vec1);
\draw[->,thick,red] (0,0) -- (vec2);
\draw[dashed] (vec2) -- ++(vec1); % This how to add a vector to another
\draw[dashed] (vec1) -- ++(vec2); % using the coordinates as vectors
\draw[->,thick,orange] (0,0) -- ($(vec1) + (vec2)$); % This is how to do arithmetic
                                                     % operations on the coordinates.
                                                     % (requires calc library of TikZ.
                                                     % See the manual )
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

它取自相量图

在此处输入图片描述

%& -shell-escape
% Phasor diagram
% Author: Urs Zellweger ([email protected])
% GNUPLOT required
\documentclass[11pt]{article}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: Phasor diagram

\end{comment}
\usepackage{ifthen}
\usepackage{pgf}
\usepackage{pgffor}
\usepgfmodule{shapes}
\usepgfmodule{plot}
\usetikzlibrary{decorations}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}

\newcommand{\Gitter}[4]{
    \draw[very thin,color=gray] (#1,#3) grid (#2,#4);
}
\newcommand{\Koordinatenkreuz}[6]{
    \draw[->, >=latex, color=green!50!black] (#1,0) -- (#2,0) node[right] {#5};
    \draw[->, >=latex, color=green!50!black] (0,#3) -- (0,#4) node[left] {#6};
}
\newcommand{\KoordinatenkreuzOhneLabelsVerschobenKeinPfeil}[5]{
    \draw[-] (#1,0) -- (#2,0);
    \draw[-] (#5,#3) -- (#5,#4);

}
\newcommand{\ZeigerdiagrammText}[4]{
\begin{tikzpicture}[scale=.72, samples=100, >=latex]

    \def\Alpha{#1}
    \def\Phase{#2}
    \def\AmplitudeSpannung{#3}
    \def\AmplitudeStrom{#4}
    \def\SpannungsWert{{\AmplitudeSpannung*sin(\Alpha)}}
    \def\StromWert{{\AmplitudeStrom*sin(\Alpha+\Phase)}}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \def\FarbeSpannung{blue!90!white}
    \def\FarbeStrom{red!90!white}
    \def\FarbeWinkelZeichnung{green}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \def\Beta{\Alpha+\Phase}
    \def\AlphaRad{\Alpha*3.141592654/180}
    \def\PhaseRad{\Phase*3.141592654/180}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \Gitter{-.1}{7.1}{-3.1}{3.1}
    \Koordinatenkreuz{-.2}{7.3}{-3.2}{3.3}{$\omega t$}{}
    \draw (1.570795,0) node[below]{$\frac{\pi}{2}$};
    \draw (3.14159,0) node[below]{${\pi}$};
    \draw (4.71238898,0) node[below]{$\frac{3\pi}{2}$};
    \draw (6.283185307,0) node[below]{${2\pi}$};
    \draw (-4,0) circle (3cm);
    \KoordinatenkreuzOhneLabelsVerschobenKeinPfeil{-7.2}{-.8}{-3.6}{3.6}{-4}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % voltage
    \draw[color=\FarbeSpannung, very thick] plot[id=voltage, domain=0:7, smooth, variable=\x] ({\x},{\AmplitudeSpannung*sin(deg(\x))}) node[right] {$U(t)$};
    % voltage circle
    \draw[color=\FarbeSpannung, loosely dashed] (-4,0) circle (\AmplitudeSpannung cm);
    % angle
    \draw[color=\FarbeWinkelZeichnung!50!black, thick] (\AlphaRad, \SpannungsWert)--(\AlphaRad,\StromWert) node[below=18pt] {$\alpha$};
    % angle in the circle
    \filldraw[fill=\FarbeWinkelZeichnung!20,draw=\FarbeWinkelZeichnung!50!black] (-4,0) -- (-3,0) arc (0:\Alpha:1) -- cycle node[right] {$\alpha$};
    % voltage pointer
    \draw[<-,color=\FarbeSpannung, very thick] (\Alpha:\AmplitudeSpannung)++(-4,0) --(-4,0);
    \draw[color=\FarbeSpannung,  dashed] (\Alpha:\AmplitudeSpannung)++(-4,0) -- (\AlphaRad,\SpannungsWert);
    % current
    \draw[color=\FarbeStrom, very thick] plot[id=current, domain=0:7, smooth, variable=\x] ({\x},{\AmplitudeStrom*sin(deg(\x+\PhaseRad)}) node[right] {$I(t)$};     
    % current circle
    \draw[color=\FarbeStrom, loosely dashed]    (-4,0) circle (\AmplitudeStrom cm);
    % current pointer
    \draw[<-,color=\FarbeStrom, very thick] (\Beta:\AmplitudeStrom)++(-4,0) --(-4,0);
    \draw[color=\FarbeStrom,  dashed](\Beta:\AmplitudeStrom)++(-4,0) -- (\AlphaRad,\StromWert);
    % phase difference
    \ifthenelse{\Phase<0}{
        \draw[snake=brace] (pi/2 ,3.3)--(pi/2-\PhaseRad ,3.3) node[above=7pt, left=10pt] {$\phi$};
    }
    {
        \draw[snake=brace] (pi/2-\PhaseRad ,3.3)--(pi/2 ,3.3) node[above=7pt, left=10pt] {$\phi$};
    }
    % angular velocity \omega
    \draw[->, xshift=-4cm]  (120:2.4cm) arc (120:170:2) node[below] {$\omega$};
\end{tikzpicture}
}
% % % % % % % % % % % % % % % % % % % % % % % % % % %

\begin{document}

\begin{preview}
% usage: {alpha}{phasedifferenceUI}{voltage}{current}{Ualpha}{Ialpha}
% resistor
\ZeigerdiagrammText{60}{0}{2.7}{1.8}

\end{preview}

\end{document}

答案3

这里有 3 种变体:对于复数a+bire^phi*i(其中是弧度角)且re^phi*i(其中以度为单位的角度)。对于第一个,您需要指定原点、a、b 和绘制样式;对于其他的,您需要指定原点、r、phi 和绘制样式:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows}

\newdimen\xorig
\newdimen\yorig

\newcommand{\sumphasor}[4]% origin, a, b, style; (for z=a+bi)
{   \path (#1);
  \pgfgetlastxy{\xorig}{\yorig}
  \pgfmathsetmacro{\xfirst}{\xorig/28.453}
  \pgfmathsetmacro{\yfirst}{\yorig/28.453}
  \pgfmathsetmacro{\xsecond}{\xorig/28.453+#2}
  \pgfmathsetmacro{\ysecond}{\yorig/28.453+#3}
  \draw[#4] (\xfirst,\yfirst) -- (\xsecond,\ysecond);
}

\newcommand{\expphasorpi}[4]% origin, r, phi(pi), style
{   \path (#1);
  \pgfgetlastxy{\xorig}{\yorig}
  \pgfmathsetmacro{\xfirst}{\xorig/28.453}
  \pgfmathsetmacro{\yfirst}{\yorig/28.453}
  \pgfmathsetmacro{\xsecond}{\xorig/28.453+#2*cos(#3/pi*180)}
  \pgfmathsetmacro{\ysecond}{\yorig/28.453+#2*sin(#3/pi*180)}
  \draw[#4] (\xfirst,\yfirst) -- (\xsecond,\ysecond);
}

\newcommand{\expphasordeg}[4]% origin, r, phi(pi), style
{   \path (#1);
  \pgfgetlastxy{\xorig}{\yorig}
  \pgfmathsetmacro{\xfirst}{\xorig/28.453}
  \pgfmathsetmacro{\yfirst}{\yorig/28.453}
  \pgfmathsetmacro{\xsecond}{\xorig/28.453+#2*cos(#3)}
  \pgfmathsetmacro{\ysecond}{\yorig/28.453+#2*sin(#3)}
  \draw[#4] (\xfirst,\yfirst) -- (\xsecond,\ysecond);
}

\begin{document}

\begin{tikzpicture}
    \draw[->] (-4,0) -- (4,0);
    \draw[->] (0,-4) -- (0,4);
    \foreach \x in {-4,...,4}
    {   \draw (-0.1,\x) -- (0.1,\x);
        \draw (\x,-0.1) -- (\x,0.1);
    }
    \sumphasor{0,0}{3}{-2}{red,->,thick}
    \sumphasor{0,0}{1}{3}{blue,->,thick}
    \sumphasor{0,0}{4}{-0.3}{green,->,thick}
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
    \draw[->] (-4,0) -- (4,0);
    \draw[->] (0,-4) -- (0,4);
    \foreach \x in {-4,...,4}
    {   \draw (-0.1,\x) -- (0.1,\x);
        \draw (\x,-0.1) -- (\x,0.1);
    }
    \expphasorpi{0,0}{3}{0.785}{red,->,thick} % pi/4
    \expphasorpi{0,0}{2}{1.047}{blue,->,thick} % 1/3*pi
    \expphasorpi{0,0}{4}{-0.785}{green,->,thick} %-pi/4
\end{tikzpicture}

\begin{tikzpicture}
    \draw[->] (-4,0) -- (4,0);
    \draw[->] (0,-4) -- (0,4);
    \foreach \x in {-4,...,4}
    {   \draw (-0.1,\x) -- (0.1,\x);
        \draw (\x,-0.1) -- (\x,0.1);
    }
    \expphasordeg{0,0}{3}{-30}{red,->,thick} % pi/4
    \expphasordeg{0,0}{2}{75}{blue,->,thick} % 2/3*pi
    \expphasordeg{0,0}{4}{-45}{green,->,thick} %-pi/4
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
    \draw[->] (-4,0) -- (4,0);
    \draw[->] (0,-4) -- (0,4);
    \foreach \x in {-4,...,4}
    {   \draw (-0.1,\x) -- (0.1,\x);
        \draw (\x,-0.1) -- (\x,0.1);
    }
    \sumphasor{0,0}{3}{-2}{red,-latex,thick}
    \sumphasor{0,0}{1}{3}{blue,-latex,thick}
    \sumphasor{3,-2}{1}{3}{densely dashed,thick}
    \sumphasor{1,3}{3}{-2}{densely dashed,thick}
    \sumphasor{0,0}{4}{1}{green!50!gray,-latex,thick}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案4

tkz 元素的基础之一是复数。点或多或少与其词缀相似。实际情况比这稍微复杂一些,因为点、线和圆都是对象(就 OOP 对象编程而言)。

对象具有诸如点的模数和参数之类的属性。您无需计算任何内容,因为 Lua 会在您创建对象时为您进行计算。

对于绘图,您可以使用 Tikz 或 tkz-euclide。对于 tkz-euclide,我刚刚完成了一个“迷你”版本,这意味着只有绘图宏可以访问。

我已经给出了一些如何使用tkzUseLua宏来检索使用 Lua 获取的值的示例。

我添加了一些额外内容:复数的乘法;您还可以将它们相除、取共轭等等。

您需要使用 lualatex 进行编译!

\documentclass{article}
\usepackage{tkz-euclide,tkz-elements}

\begin{document}
\begin{tkzelements}
   scale = 1
   z.O   = point : new ( 0 , 0 )
   z.I   = point : new ( 2 , 0 )
   z.v1  = point : polar ( 1 , math.pi/3 )
   z.v2  = point : polar ( 2 , math.pi/9 )
   z.V   = z.v1+z.v2
   z.P   = z.v1 * z.v2
\end{tkzelements}
   
\begin{tikzpicture}[>=latex,gridded]
\tkzGetNodes
\tkzDrawSegment[->,thick,blue](O,v1)
\tkzDrawSegment[->,thick,red](O,v2)
\tkzDrawSegment[->,thick,purple](O,V)
\tkzDrawSegment[->,thick,cyan](O,P)
\tkzDrawSegments[dashed](v1,V v2,V)
\tkzDrawArc[->](O,I)(P)
\tkzLabelArc[pos=.75,anchor = west](O,I,P){arg(v1)+arg(v2)=80°}
\end{tikzpicture}

\parindent=0pt
The modulus of V is \tkzUseLua{tkzround(z.V.modulus,5)}\\
The argument of V is \tkzUseLua{tkzround(z.V.argument,5)} rad either \tkzUseLua{tkzround(z.V.argument /math.pi *180,5)}° .

v1 : \tkzUseLua{tkzround(z.v1.re,5)} + \tkzUseLua{tkzround(z.v1.im,5)} i\\
v2 : \tkzUseLua{tkzround(z.v2.re,5)} + \tkzUseLua{tkzround(z.v2.im,5)} i\\
V : \tkzUseLua{tkzround(z.V.re,5)} + \tkzUseLua{tkzround(z.V.im,5)} i\\
P : argument = \tkzUseLua{tkzround(z.P.argument /math.pi *180,5)}° .
\end{document}

在此处输入图片描述

相关内容