回答后更新:

回答后更新:

回答后更新:

  • 在使用下面非常有用的答案后,我的动画现在看起来像这样,并且所有标签都“粘”在了适当的位置。非常感谢!* 在此处输入图片描述

原始问题:

我有以下旋转动画: fubar 箭头标签

如您所见,标签的行为很奇怪,尤其是红色标签和 35 度角标签。是否可以将标签附加到相对于箭头的固定点,该点在旋转箭头时不会发生变化?

我的全部代码都在这里,有问题的标签位于第 239、257 和 280 行。

\documentclass[tikz,border=10pt]{standalone}
\usepackage{ifthen}
\usepackage{pgfplots}
\usepackage{amsmath} % Required for \varPsi below
\usepackage{tikz}
\usepackage{animate}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.9}

\newcommand{\gettikzxy}[3]{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef#2{\the\pgf@x}%
  \edef#3{\the\pgf@y}%
}

\begin{document}
\foreach \angle in {1,2,...,3}{ %Create all the frames with different angle  (DEFAULT IS {360,359,...,1} - but that takes about 20min rendering time) 

    \begin{tikzpicture}


    %Definitions - These can be changed to create new figures%
    %===========================================================
    \pgfmathsetmacro \Vmax {8/3}; %Max phase voltage (in cm) (8/3 or 2.667 cm is default as that will create a 4 cm space vector)
    %\def \Vs {4}; %Magnitude of space vector in cm OLD
    \def \Angle {\angle}; %Angle with regards to phase A
    \def \Osv {35}; %Angle of d-axis wrt space vector
    \def \R {2.5}; %Magnitude of rotor flux in cm



    %Calculated variables. These should not be changed unless you know what you are doing%
    %===========================================================
    \pgfmathsetmacro \Vs {\Vmax * 1.5};  %Magnitude of space vector in cm
    \pgfmathsetmacro \MaxLin {\Vs * cos{30}}; %Magnitude before overmodulation
    \pgfmathsetmacro \Qmag {\Vs * sin{\Osv})}; %Magnitude of Q axis
    \pgfmathsetmacro \Dmag {\Vs * cos{\Osv})}; %Magnitude of Q axis
    \pgfmathsetmacro \Marker {\Angle/45)};
    %\pgfmathsetmacro \Vmax {\Vs * 2/3}; %Max phase voltage (OLD)
    \def \Axisheight {\Vmax *3};
    \pgfmathsetmacro \Va {\Vmax * sin{(\Angle+0)}}; %Magnitude of phase A at angle \Angle
    \pgfmathsetmacro \Vb {\Vmax * sin{(\Angle+120)}}; %Magnitude of phase B at angle \Angle
    \pgfmathsetmacro \Vc {\Vmax * sin{(\Angle+240)}}; %Magnitude of phase C at angle \Angle
    \pgfmathsetmacro \Radius {\Vmax}; %Radius of maximum line to line voltage output


    %Locations%
    %===========================================================
    \def \OrigoX {-6 cm}; % If you want to move the circle relative to the wave forms (default -6cm)
    \def \OrigoY {0 cm};
    \def \OrigoYb {-11 cm};
    \def \OrigoYc {-22 cm};
    \coordinate (origo) at (\OrigoX,\OrigoY); %Center of top phasor diagram
    \coordinate (origob) at (\OrigoX,\OrigoYb); %Center of center phasor diagram
    \coordinate (origoc) at (\OrigoX,\OrigoYc); %Center of bottom phasor diagram
    \coordinate (phase_a) at (0:\Va cm); %Tip of phase A
    \coordinate (phase_b) at (120:\Vb cm); %Tip of phase B
    \coordinate (phase_c) at (240:\Vc cm) ; %Tip of phase C
    \coordinate (Y) at (\OrigoX+\Vs cm ,\OrigoY+0); %Where to start the Hexagon


    %Circle background rings%
    %===========================================================
    \node at (origo) [circle,thick,draw=black!80,fill=red!0, inner sep=0pt,minimum size=\Vs*2 cm] {}; %Top Circle with radius 128% 
    \node at (origob) [circle,thick,draw=black!80,fill=red!0, inner sep=0pt,minimum size=\Vs*2 cm] {}; %Center Circle with radius 128% 
    \node at (origoc) [circle,thick,draw=black!80,fill=red!0, inner sep=0pt,minimum size=\Vs*2 cm] {}; %Center Circle with radius 128% 

    %Left axis to top circle
    \draw[<->] (1.95*\OrigoX,-1.1*\Vs cm) -- (1.95*\OrigoX,1.1*\Vs cm) node[anchor=south, distance=0.2cm]{$I$};
    \draw [color=black,dotted](\OrigoX,\Vs cm)--(2*\OrigoX,\Vs cm) node[anchor=east, distance=0.5cm] {$\frac{3}{2}i - 150\%$};
    %\draw [color=red,dotted] (\OrigoX,\MaxLin cm) -- (2*\OrigoX,\MaxLin cm) node[anchor=east, distance=0.5cm] {$\frac{2\sqrt{3}}{3}I_{max} - 115,5\%$};
    \draw [color=black,dotted](\OrigoX,\Vmax cm) -- (2*\OrigoX,\Vmax cm) node[anchor=east] {$i - 100\%$};
    \draw [color=black,dotted](\OrigoX,0 cm) -- (2*\OrigoX,0 cm) node[anchor=east] {$0\%$};


    %Hexagon Framing around phasors%
    %===========================================================
    %\draw[-, color=black!50,thin,dashed] (Y) -- ++(120:\Vs cm) -- ++(180:\Vs cm) -- ++(240:\Vs cm) -- ++(300:\Vs cm) -- ++(360:\Vs cm) -- ++(60:\Vs cm); % Six step hexagon
    %\node at (origo) [circle,draw=red!80, inner sep=0pt,minimum size=\MaxLin*2 cm] {}; %Circle with radius 115% 



    %Black guide lines with angle notation
    \foreach \x in {45,90,...,360} {
        \draw[-,color=black,dotted, thin] (origo)  -- ++(\x:\Vs cm) node[label={[label distance=-0.18cm]\x: $\x^{\circ}$}] {};
    } \foreach \x in {45,90,...,360} {
        \draw[-,color=black,dotted, thin] (origob)  -- ++(\x:\Vs cm) node[label={[label distance=-0.18cm]\x: $\x^{\circ}$}] {};
    } \foreach \x in {45,90,...,360} {
        \draw[-,color=black,dotted, thin] (origoc)  -- ++(\x:\Vs cm) node[label={[label distance=-0.18cm]\x: $\x^{\circ}$}] {};
    } 





    %=============================================================================================================
    %Actual three phase phasors%
    %=============================================================================================================

    \node [above, align=center] at (0,4.5) [anchor=south]  {\large Three-phased current meassurement: $i_a$, $i_b$, $i_c$}; %Label overhead figure 1
    \node at (origo) [circle,thick,draw=black!80, inner sep=0pt,minimum size=\Vmax*2 cm] {}; %Circle with radius 100%
    \draw[->,color=red, very thick] (origo)  -- ++(phase_a); %Phase A phasor
    \draw[->,color=blue, very thick] (origo)  -- ++(phase_b); %Phase B phasor
    \draw[->,color=green, very thick] (origo)  -- ++(phase_c); %Phase C phasor

    \draw[color=red,thick,smooth,domain=0:8] plot(\x,{\Vmax * sin(\x*45)}); % Phase A
    \draw[color=blue,thick,,smooth,domain=0:8] plot(\x,{\Vmax * sin((\x*45)+120)}); %Phase B
    \draw[color=green,thick,,smooth,domain=0:8] plot(\x,{\Vmax * sin((\x*45)+240)}); % Phase C

    \draw[color=red,dashed] (\Marker,\Va) -- (-0.3,\Va)  node[anchor=east] {$i_a$};; %A phase line to Y-axis
    \draw[color=blue,dashed] (\Marker,\Vb)-- (-0.3,\Vb)  node[anchor=east] {$i_b$};; %B phase line to Y-axis
    \draw[color=green,dashed] (\Marker,\Vc)-- (-0.3,\Vc)  node[anchor=east] {$i_c$};; %C phase line to Y-axis

    %SPACE VECTOR %
    \draw[->,ultra thick,black] (origo) -- ++($(phase_a) + (phase_b) + (phase_c)$) coordinate(Vstip); %Space vector resultant
    \pgfgetlastxy{\XCoord}{\YCoord}; % X and Y coordinates of Space vector tip

    %Find space vector angle
    \pgfmathanglebetweenpoints{\pgfpointanchor{origo}{center}}{\pgfpointanchor{Vstip}{center}}
    \let\PhaseBlack\pgfmathresult;

    %Phasor guide lines%
    \draw[-,color=red, dashed] (origo)  -- ++(0:\Vmax cm)  node[anchor=west] {\large $i_a$};
    \draw[-,color=blue, dashed] (origo) -- ++(120:\Vmax cm) node[anchor=south] {\large $i_b$};
    \draw[-,color=green, dashed] (origo)  -- ++(240:\Vmax cm) node[anchor=north] {\large $i_c$};

    \draw[-,color=red, dashed] (origo)  -- ++(0:-\Vmax cm) node[anchor=east] {$-i_a$};
    \draw[-,color=blue, dashed] (origo) -- ++(120:-\Vmax cm)  node[anchor=north] {$-i_b$};
    \draw[-,color=green, dashed] (origo)  -- ++(240:-\Vmax cm) node[anchor=south] {$-i_c$};

    \draw[->,color=blue, thin] (origo) ++(phase_a) -> ++(phase_b); %Resultant help lines
    \draw[->,color=green, thin] (origo) ++(phase_a) ++(phase_b) -> ++(phase_c); %Resultant help lines

    \draw[color=gray] (\OrigoX,\Vmax) -- (9,\Vmax) ; %X axis TOP inner
    \draw[color=gray] (\OrigoX,-\Vmax) -- (9,-\Vmax) ; %X axis bottom inner


    %% Rotor Flux Vector%
    %\coordinate (rfluxtip) at (\PhaseBlack-\Osv:\R); %Tip of rotor flux
    %\draw[->,color=gray] (origo)  -- ++(rfluxtip)  node[label={[label distance=-0.18cm]\PhaseBlack-\Osv: $\lambda_r$}] {}; %Rotor Flux Phasor


    %Wave form
    \draw[->, color=black] (0,0) -- (9,0) node[anchor=west] {$\theta$}; %X axis
    \draw[->, color=black] (0,-\Vs) -- (0,\Vs) node[anchor=south] {$i$}; %Y axis
    %\draw[help lines] (0,-\Vs) grid (9 ,\Vs); %Grid


    %X Axis help lines
    \foreach \x in {1, 2,...,8} {
        \draw[color=lightgray] (\x cm,\Vs cm) -- (\x cm,-\Vs cm)  {};
        }
    %X Axis tick marks
    \foreach \x in {1, 2,...,8} {
        \pgfmathsetmacro \tick {\x * 45};
        \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {\small\pgfmathprintnumber[fixed, precision=10]{\tick}$^{\circ}$};
        }

    %Marker to illustrate angle position over wave forms
    \draw[color=black] (\Marker cm, \Vs cm) -- (\Marker cm, -\Vs cm) node[anchor=north,align=center]{$\Angle^{\circ}$}; 

    %Top and bottom border, extending to circle top and and bottom
    \draw[color=gray] (\OrigoX,\Vs) -- (9,\Vs) ; %X axis TOP outer
    \draw[color=gray] (\OrigoX,-\Vs) -- (9,-\Vs) ; %X axis bottom outer










    %=============================================================================================================
    %Alpha and Beta Phasors
    %=============================================================================================================

    \node [above, align=center] at (0,-6.5) [anchor=south]  {\large Clarke Transformation: $i_\alpha$, $i_\beta$};  %Label overhead figure 2

    %SPACE VECTOR %
    \draw[->,ultra thick,black] (origob) -- ++($(phase_a) + (phase_b) + (phase_c)$) coordinate(Vstipb); %Space vector resultant
    \pgfgetlastxy{\XCoordb}{\YCoordb}; % X and Y coordinates of Space vector tip

    %Find space vector angle
    \pgfmathanglebetweenpoints{\pgfpointanchor{origob}{center}}{\pgfpointanchor{Vstipb}{center}}
    \let\PhaseBlackb\pgfmathresult;

    %Green Axis system rotated to rotor angle
    \draw[-,color=green] (\OrigoX,\OrigoYb-\Vs cm) -- ++(90:2*\Vs cm);
    \draw[-,color=green] (\OrigoX+\Vs cm,\OrigoYb)  -- ++(0:-2*\Vs cm);

    \draw[->,color=violet, thin, dashed] (\OrigoX, \YCoordb) -> (Vstipb); %Beta help Line
    \draw[->,color=orange, thin, dashed] (\XCoordb, \OrigoYb) -> (Vstipb); %Alpha help Line

    \draw[->,color=violet, very thick] (origob)  -- ++(0,\YCoordb-\OrigoYb) node[anchor=north east] {\large $i_\beta$}; %Phase beta phasor
    \draw[->,color=orange, very thick] (origob)  -- ++(\XCoordb-\OrigoX,0) node[anchor=north] {\large $i_\alpha$}; %Phase alpha phasor

    \coordinate (origobb) at (0,\OrigoYb); %Center of center phasor diagram
    \draw[color=violet,thick,smooth,domain=0:8, shift=(origobb)]  plot(\x,{\Vs * sin((\x*45)+90)}); % Beta wave form
    \draw[color=orange,thick,smooth,domain=0:8, shift=(origobb)]  plot(\x,{\Vs * sin((\x*45)+0)}); % Alpha wave form

    \draw[color=violet,dashed] (\Marker,\YCoordb)-- (-0.3,\YCoordb)  node[anchor=east] {$i_\beta$};; %Beta line to beta-axis
    \draw[color=orange,dashed] (\Marker,\XCoordb-\OrigoX+\OrigoYb)-- (-0.3,\XCoordb-\OrigoX+\OrigoYb)  node[anchor=east] {$i_\alpha$};; %Alpha line to alpha-axis

    %Wave form
    \draw[->, color=black] (0,\OrigoYb) -- (9,\OrigoYb) node[anchor=west] {$\theta$}; %X axis middle
    \draw[->, color=black] (0,\OrigoYb-\Vs cm) -- (0,\OrigoYb+\Vs cm) node[anchor=south] {$i$}; %Y axis middle
    \draw[help lines] (0,\OrigoYb-\Vs cm) grid (9 ,\OrigoYb+\Vs cm); %Grid middle

    %X Axis tick marks
    \foreach \x in {1, 2,...,8} {
        \pgfmathsetmacro \tick {\x * 45};
        \draw (\x cm,\OrigoYb-1pt) -- (\x cm,\OrigoYb+1pt) node[anchor=north] {\small\pgfmathprintnumber[fixed, precision=10]{\tick}$^{\circ}$};
        }

    %Marker to illustrate angle position over wave forms
    \draw[color=black] (\Marker cm,\OrigoYb+\Vs cm) -- (\Marker cm, \OrigoYb-\Vs cm) node[anchor=north,align=center]{ $\Angle^{\circ}$}; 

    %Top and bottom border, extending to circle top and and bottom
    \draw[color=gray] (\OrigoX,\OrigoYb+\Vs cm) -- (9,\OrigoYb+\Vs cm) ; %X axis TOP outer
    \draw[color=gray] (\OrigoX,\OrigoYb-\Vs cm) -- (9,\OrigoYb-\Vs cm) ; %X axis bottom outer









    %=============================================================================================================
    %%D and Q Phasors%
    %=============================================================================================================

    \node [above, align=center] at (0,-17.5) [anchor=south]  {\large Park Transformation: $i_d$, $i_q$};    %Label overhead figure 3

    %Space Vector
    \draw[->,ultra thick,black] (origoc) -- ++($(phase_a) + (phase_b) + (phase_c)$) node[label={[label distance=0.1 cm,,rotate=\PhaseBlackb-90, color=red]\PhaseBlackb-90: $\lambda_{stator}$}] {} coordinate(Vstipc); %Space vector resultant
    \pgfgetlastxy{\XCoordc}{\YCoordc}; % X and Y coordinates of Space vector tip

    %Find space vector angle
    \pgfmathanglebetweenpoints{\pgfpointanchor{origoc}{center}}{\pgfpointanchor{Vstipc}{center}}
    \let\PhaseBlackc\pgfmathresult;

    \coordinate (d1c) at (\PhaseBlackc-\Osv:\Vs cm) ; %Tip of d axis
    \coordinate (d2c) at (\PhaseBlackc-\Osv:-\Vs cm) ; %Tip of d axis
    \coordinate (q1c) at (\PhaseBlackc-\Osv+90:\Vs cm) ; %Tip of q axis
    \coordinate (q2c) at (\PhaseBlackc-\Osv+90:-\Vs cm) ; %Tip of q axis

    \coordinate (d3c) at (\PhaseBlackc-\Osv+90:\Qmag) ; %Tip of d 
    \coordinate (q3c) at (\PhaseBlackc-\Osv:\Dmag) ; %Tip of q 

    \draw[->,color=orange, thin, dashed] (origoc)  -- ++(d3c) -> (Vstipc); %Q help Line
    \draw[->,color=violet, thin, dashed] (origoc)  -- ++(q3c) -> (Vstipc); %Q help Line

    \draw[->,color=green, thick] (origoc)  -- ++(d1c) node[label={[label distance=0.1 cm,rotate=\PhaseBlackc-\Osv-90, color=red]\PhaseBlackc-\Osv-90: $\lambda_{rotor}$}] {}; %D axis help line
    \draw[-,color=green, thin] (origoc)  -- ++(d2c); %D axis help line
    \draw[-,color=green, thick] (origoc)  -- ++(q1c); %Q axis help line
    \draw[-,color=green, thin] (origoc)  -- ++(q2c); %Q axis help line

    \draw[->,color=orange, very thick] (origoc)  -- ++(d3c) node[label={[label distance=-0.18cm]\PhaseBlackc-\Osv+90:\large $i_q$}] {}; %q phasor
    \draw[->,color=violet, very thick] (origoc)  -- ++(q3c) node[label={[label distance=-0.18cm]\PhaseBlackc-\Osv:\large $i_d$}] {}; %d phasor

    \coordinate (origocc) at (0,\OrigoYc); %Center of center phasor diagram
    \draw[color=orange,thick,,smooth,domain=0:8, shift=(origocc)] plot(\x,{\Qmag}); % Q
    \draw[color=violet,thick,,smooth,domain=0:8, shift=(origocc)] plot(\x,{\Dmag}); % D

    \draw[color=orange,dashed] (0,\OrigoYc+\Qmag cm)-- (-0.3,\OrigoYc+\Qmag cm)  node[anchor=east] {$i_q$}; %d line to y axis
    \draw[color=violet,dashed] (0,\OrigoYc+\Dmag cm)-- (-0.3,\OrigoYc+\Dmag cm)  node[anchor=east] {$i_d$}; %q line to y axis

    %% Rotor Flux Vector%
    %\coordinate (rfluxtipc) at (\PhaseBlackc-\Osv:\R); %Tip of rotor flux
    %\draw[->,color=yellow, thick] (origoc)  -- ++(rfluxtipc)  node[anchor=west] {$\lambda_r$}; %Bottom Rotor Flux Phasor

    % angular velocity \omega
    \draw[->] (\OrigoX,\OrigoYc) ++(\PhaseBlackc-10:.85*\Vs) arc (\PhaseBlackc-10:\PhaseBlackc+10:.85*\Vs) node[label={[label distance=0.1 cm,rotate=\PhaseBlackc-90]left: $\omega_{m}$}] {};

    % Angle between rotor and stator
    \draw[->, thick] (\OrigoX,\OrigoYc) ++(\PhaseBlackc-\Osv:.35*\Vs) arc (\PhaseBlackc-\Osv:\PhaseBlackc:.35*\Vs) node[label={[label distance=0.0 cm]below: \small $\Osv^{\circ}$}] {};

    %WAVE FORM%
    \draw[->, color=black] (0,\OrigoYc) -- (9,\OrigoYc) node[anchor=west] {$\theta$}; %X axis bottom
    \draw[->, color=black] (0,\OrigoYc-\Vs cm) -- (0,\OrigoYc+\Vs cm) node[anchor=south] {$i$}; %Y axis bottom
    \draw[help lines] (0,\OrigoYc-\Vs cm) grid (9 ,\OrigoYc+\Vs cm); %Grid middle

    %X Axis tick marks
    \foreach \x in {1, 2,...,8} {
        \pgfmathsetmacro \tick {\x * 45};
        \draw (\x cm,\OrigoYc-1pt) -- (\x cm,\OrigoYc+1pt) node[anchor=north] {\small\pgfmathprintnumber[fixed, precision=10]{\tick}$^{\circ}$};
        }

    %Marker to illustrate angle position over wave forms
    \draw[color=black] (\Marker cm,\OrigoYc+\Vs cm) -- (\Marker cm, \OrigoYc-\Vs cm) node[anchor=north,align=center]{$\Angle^{\circ}$}; 

    %Top and bottom border, extending to circle top and and bottom
    \draw[color=gray] (\OrigoX,\OrigoYc+\Vs cm) -- (9,\OrigoYc+\Vs cm) ; %X axis TOP outer
    \draw[color=gray] (\OrigoX,\OrigoYc-\Vs cm) -- (9,\OrigoYc-\Vs cm) ; %X axis bottom outer


    \end{tikzpicture}}
\end{document}

如果要创建动画,您还应该在同一文件夹中的单独文件中编写此代码:(然后上述代码应命名为“frames2”)还要注意第一个文件第 17 行的注释。完整的 360 度渲染需要大量时间,因此我通常在测试时以 4 个不同的角度渲染以检查结果(例如 \foreach \angle in {1,90,180,270})。

\documentclass{standalone} 
\usepackage{animate} 

\begin{document} 
\animategraphics[controls,autoplay,loop]{72}{frames2}{}{} %Create animation of the output file with all the frames
\end{document} 

答案1

这里有两个生成“附加标签”的示例,一个使用transform shape,另一个使用旋转校正。

\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \foreach \i in {0,30,..., 330}
    \draw[red, ->, rotate=\i, transform shape] (0,0) -- +(0:3) node[rotate=-90,above]{fixed};
  \foreach \i in {0,30,..., 330}
    \draw[->] (7,0) -- +(\i:3) node[rotate=\i-90,above]{fixed};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容