如何用 TikZ 绘制欧拉角旋转序列?

如何用 TikZ 绘制欧拉角旋转序列?

对于一些讲义,我想用欧拉角来说明连续的单位轴旋转。到目前为止,我对我的想法很满意:

欧拉角单位轴旋转

但是,我无法在连续旋转之间绘制角度。例如,我希望在和等theta_1之间。如下所示: x_Ix'期望输出的示例

其中的线条应该(理想情况下......)是弧,并且带有标签。

我使用该包通过以下代码实现了上面图片中的最后一张tikz-3dplot

\begin{tikzpicture}[scale=2.5,tdplot_main_coords]

% Set origin of main (body) coordinate system
\coordinate (O) at (0,0,0);

% Draw main coordinate system
\draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$}; 

% Intermediate frame 1
\tdplotsetrotatedcoords{\zRot}{0}{0}
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (1,0,0) node[anchor=north east]{$x'$};
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,1,0) node[anchor=west]{$y'$};
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,0,1) node[anchor=west]{$z'$};

% Intermediate frame 2
\tdplotsetrotatedcoords{\zRot}{\yRot}{0}
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (1,0,0) node[anchor=
north]{};
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,1,0)
node[anchor=west]{$y''$};
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,0,1)
node[anchor=south]{$z''$};

% Rotate to final frame
\tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0)
node[anchor=west]{$x_{\mathcal{B}}$, \textcolor{green}{$x''$}};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};

\end{tikzpicture}

完整的代码粘贴在这里,以免太拥挤:
http://pastebin.com/pYW6iyEP

长话短说:如何在各个坐标系之间绘制弧线?

答案1

您可以使用 解决问题\tdplotdrawarc[coordinates_frame,->,colo]{origin}{radius}{start angle}{end angle}{node info}{label}
在使用它之前,您可能需要使用 旋转 theta 平面。我发现使用起来有点不直观/很难想象角度应该是多少。因此,首先使用 绘制一个完整的圆并调整角度直到圆处于正确的平面\tdplotsetrotatedthetaplanecoords{angle}可能会有所帮助。\tdplotdrawarc[coordinates_frame,->,colo]{origin}{radius}{0}{360}{node info}{label}\tdplotsetrotatedthetaplanecoords{angel}

第三张图片的解决方案是:

\begin{tikzpicture}[scale=2.5,tdplot_main_coords]

% Set origin of main (body) coordinate system
\coordinate (O) at (0,0,0);

% Draw main coordinate system
\draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};



% Intermediate frame 1
\tdplotsetrotatedcoords{\zRot}{0}{0}
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (1,0,0) node[anchor=north east]{$x'$};
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,1,0) node[anchor=west]{$y'$};
\draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,0,1) node[anchor=west]{$z'$};

\tdplotsetrotatedthetaplanecoords{90}
%draw theta arc and label
%\tdplotdrawarc[tdplot_rotated_coords,->,color=blue]{(0,0,0)}{0.5}{0}{350}{anchor=south west,color=gray}{$\alpha$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{80}{90}{anchor=south west,color=gray}{$\alpha$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{170}{180}{anchor=south west,color=gray,  yshift = -15 pt}{$\alpha$}

%% Intermediate frame 2
\tdplotsetrotatedcoords{\zRot}{\yRot}{0}
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (1,0,0) node[anchor=
north]{};
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,1,0)
node[anchor=west]{$y''$};
\draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,0,1)
node[anchor=south]{$z''$};
\tdplotsetrotatedthetaplanecoords{60}
%draw theta arc and label
%\tdplotdrawarc[tdplot_rotated_coords,->,color=green]{(0,0,0)}{0.5}{0}{350}{anchor=north,color=gray}{$\beta$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{80}{90}{anchor=north,color=gray}{$\beta$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{310}{320}{anchor=south west,color=gray}{$\beta$}
% 
% Rotate to final frame
\tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0)
node[anchor=west]{$x_{\mathcal{B}}$, \textcolor{green}{$x''$}};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};

\tdplotsetrotatedthetaplanecoords{30}
%draw theta arc and label
%\tdplotdrawarc[tdplot_rotated_coords,->,color=cyan]{(0,0,0)}{0.5}{0}{350}{anchor=north,color=gray}{$\gamma$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{215}{225}{anchor=north,color=gray, yshift = 15pt}{$\gamma$}
\tdplotdrawarc[tdplot_rotated_coords,->,color=gray]{(0,0,0)}{0.5}{328}{338}{anchor=south west,color=gray}{$\gamma$}

\end{tikzpicture}

第三帧的解决方案

答案2

我遇到了同样的问题,Zwähnia 的解决方案很棒,在使用欧拉角的情况下非常有效,但无法帮助我解决 Tait-Bryan 角问题。这有点 bug,我还没能找到原因,所以有一个解决方法。

我遇到的问题来自于你重新定义了命令\tdplotcalctransformrotmain(我也是)。这在某种程度上让 tikz-3dplot 变得疯狂。正如您在第一个图中看到的,使用 tikz-3dplot 实现旋转,圆在平面上绘制z_B - x_B(蓝色圆)、y_B - z_B(红色圆)和x_B - y_B(黑色圆),而在 Tait-Bryan 的情况下,红色和黑色圆在同一平面上 欧拉与 Tait-Bryan 的比较

但代码很相似...

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
% Workaround for making use of externalization possible
% -> remove hardcoded pdflatex and replace by lualatex
\usepgfplotslibrary{external}

% Redefine rotation sequence for tikz3d-plot to z-y-x
\newcommand{\tdseteulerxyz}{
  \renewcommand{\tdplotcalctransformrotmain}{%
    %perform some trig for the Euler transformation
      \tdplotsinandcos{\sinalpha}{\cosalpha}{\tdplotalpha}
    \tdplotsinandcos{\sinbeta}{\cosbeta}{\tdplotbeta}
    \tdplotsinandcos{\singamma}{\cosgamma}{\tdplotgamma}
    %
      \tdplotmult{\sasb}{\sinalpha}{\sinbeta}
    \tdplotmult{\sasg}{\sinalpha}{\singamma}
    \tdplotmult{\sasbsg}{\sasb}{\singamma}
    %
      \tdplotmult{\sacb}{\sinalpha}{\cosbeta}
    \tdplotmult{\sacg}{\sinalpha}{\cosgamma}
    \tdplotmult{\sasbcg}{\sasb}{\cosgamma}
    %
      \tdplotmult{\casb}{\cosalpha}{\sinbeta}
    \tdplotmult{\cacb}{\cosalpha}{\cosbeta}
    \tdplotmult{\cacg}{\cosalpha}{\cosgamma}
    \tdplotmult{\casg}{\cosalpha}{\singamma}
    %
      \tdplotmult{\cbsg}{\cosbeta}{\singamma}
    \tdplotmult{\cbcg}{\cosbeta}{\cosgamma}
    %
      \tdplotmult{\casbsg}{\casb}{\singamma}
    \tdplotmult{\casbcg}{\casb}{\cosgamma}
    %
      %determine rotation matrix elements for Euler transformation
      \pgfmathsetmacro{\raaeul}{\cacb}
    \pgfmathsetmacro{\rabeul}{\casbsg - \sacg}
    \pgfmathsetmacro{\raceul}{\sasg + \casbcg}
    \pgfmathsetmacro{\rbaeul}{\sacb}
    \pgfmathsetmacro{\rbbeul}{\sasbsg + \cacg}
    \pgfmathsetmacro{\rbceul}{\sasbcg - \casg}
    \pgfmathsetmacro{\rcaeul}{-\sinbeta}
    \pgfmathsetmacro{\rcbeul}{\cbsg}
    \pgfmathsetmacro{\rcceul}{\cbcg}
  }
}

% Set the plot display orientation
% Syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{60}{140}

\pgfmathsetmacro{\zRot}{10}
\pgfmathsetmacro{\yRot}{10}
\pgfmathsetmacro{\xRot}{10}
%%%%%%%%% Using standard euler angles implemented in default tikz-3dplot implementation
\begin{document}
%%%%%%%%%%%%% Z-Y-Z
\begin{tikzpicture}[scale=2.5,tdplot_main_coords]

% Set origin of main (body) coordinate system
\coordinate (O) at (0,0,0);

% Draw main coordinate system
\draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};

% Rotate to final frame
\tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0) node[anchor=west]{$x_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};

%Draws circle representing the rotated planes. Each of these should be "pointed" by two arrows.
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=black]{(0,0,0)}{1}{0}{350}{anchor=south west,color=black}{$x-y$}
\tdplotsetrotatedthetaplanecoords{0}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=blue]{(0,0,0)}{1}{0}{350}{anchor=south west,color=blue}{$x-z$}
\tdplotsetrotatedthetaplanecoords{90}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=red]{(0,0,0)}{1}{0}{350}{anchor=south west,color=red}{$y-z$}
\end{tikzpicture}

%%%%%% Change the rotation matrix in order to use Tait-Bryan angles
\tdseteulerxyz
%%%%%%%%%%%%% Z-Y-X
\begin{tikzpicture}[scale=2.5,tdplot_main_coords]

% Set origin of main (body) coordinate system
\coordinate (O) at (0,0,0);

% Draw main coordinate system
\draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};

% Rotate to final frame
\tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0) node[anchor=west]{$x_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};

%Draws circle representing the rotated planes. Each of these should be "pointed" by two arrows.
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=black]{(0,0,0)}{1}{0}{350}{anchor=south west,color=black}{$x-y$}
\tdplotsetrotatedthetaplanecoords{0}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=blue]{(0,0,0)}{1}{0}{350}{anchor=south west,color=blue}{$x-z$}
\tdplotsetrotatedthetaplanecoords{90}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=red]{(0,0,0)}{1}{0}{350}{anchor=south west,color=red}{$y-z$}
\end{tikzpicture}
\end{document}

我想保留角度宏的使用\xRot\yRot\zRot如果您像 Zwähnia 那样设置,则不再可能使用tdplotsetrotatedthetaplanecoordsTait-Bryan 的工作表现

我的解决方案是将坐标向后旋转,以便轻松找到好的 θ 平面。

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
% Workaround for making use of externalization possible
% -> remove hardcoded pdflatex and replace by lualatex
\usepgfplotslibrary{external}

% Redefine rotation sequence for tikz3d-plot to z-y-x
\newcommand{\tdseteulerxyz}{
  \renewcommand{\tdplotcalctransformrotmain}{%
    %perform some trig for the Euler transformation
      \tdplotsinandcos{\sinalpha}{\cosalpha}{\tdplotalpha}
    \tdplotsinandcos{\sinbeta}{\cosbeta}{\tdplotbeta}
    \tdplotsinandcos{\singamma}{\cosgamma}{\tdplotgamma}
    %
      \tdplotmult{\sasb}{\sinalpha}{\sinbeta}
    \tdplotmult{\sasg}{\sinalpha}{\singamma}
    \tdplotmult{\sasbsg}{\sasb}{\singamma}
    %
      \tdplotmult{\sacb}{\sinalpha}{\cosbeta}
    \tdplotmult{\sacg}{\sinalpha}{\cosgamma}
    \tdplotmult{\sasbcg}{\sasb}{\cosgamma}
    %
      \tdplotmult{\casb}{\cosalpha}{\sinbeta}
    \tdplotmult{\cacb}{\cosalpha}{\cosbeta}
    \tdplotmult{\cacg}{\cosalpha}{\cosgamma}
    \tdplotmult{\casg}{\cosalpha}{\singamma}
    %
      \tdplotmult{\cbsg}{\cosbeta}{\singamma}
    \tdplotmult{\cbcg}{\cosbeta}{\cosgamma}
    %
      \tdplotmult{\casbsg}{\casb}{\singamma}
    \tdplotmult{\casbcg}{\casb}{\cosgamma}
    %
      %determine rotation matrix elements for Euler transformation
      \pgfmathsetmacro{\raaeul}{\cacb}
    \pgfmathsetmacro{\rabeul}{\casbsg - \sacg}
    \pgfmathsetmacro{\raceul}{\sasg + \casbcg}
    \pgfmathsetmacro{\rbaeul}{\sacb}
    \pgfmathsetmacro{\rbbeul}{\sasbsg + \cacg}
    \pgfmathsetmacro{\rbceul}{\sasbcg - \casg}
    \pgfmathsetmacro{\rcaeul}{-\sinbeta}
    \pgfmathsetmacro{\rcbeul}{\cbsg}
    \pgfmathsetmacro{\rcceul}{\cbcg}
  }
}

% Set the plot display orientation
% Syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{60}{140}

\pgfmathsetmacro{\zRot}{10}
\pgfmathsetmacro{\yRot}{10}
\pgfmathsetmacro{\xRot}{10}
%%%%%%%%% Using standard euler angles implemented in default tikz-3dplot implementation
\begin{document}
%%%%%% Change the rotation matrix in order to use Tait-Bryan angles
\tdseteulerxyz
%%%%%%%%%%%%% Z-Y-X
\begin{tikzpicture}[scale=2.5,tdplot_main_coords]

% Set origin of main (body) coordinate system
\coordinate (O) at (0,0,0);

% Draw main coordinate system
\draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
\draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};

% Rotate to final frame
\tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0) node[anchor=west]{$x_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
\draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};

%Draws circle representing the rotated planes. Each of these should be "pointed" by two arrows.
%\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=black]{(0,0,0)}{1}{0}{350}{anchor=south west,color=black}{$x-y$}
\tdplotsetrotatedthetaplanecoords{0}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=blue]{(0,0,0)}{1}{0}{350}{anchor=south west,color=blue}{$x-z$}
\tdplotsetrotatedthetaplanecoords{90}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=black]{(0,0,0)}{1}{0}{350}{anchor=south west,color=black}{$y-z$}

% Instead, rotates in the opposite direction
\tdplotsetrotatedcoords{\zRot+90}{\yRot}{\xRot}
%Draw the last circle in the right plane
\tdplotsetrotatedthetaplanecoords{0}
\tdplotdrawarc[dashed,tdplot_rotated_coords,->,color=red]{(0,0,0)}{1}{0}{350}{anchor=south west,color=red}{$x-z$}

\end{tikzpicture}
\end{document}

它并不是很漂亮,但它的优点是可以使用角度宏并允许按照我想要的方式绘制序列(我完成了我最后的 tikzpicture 并用它更新了我的答案)。

希望这可以帮助。

干杯。

答案3

这是基于另外两个参数化的不同提议——欧拉 zxz 和卡丹 xyz。完整代码可在此处找到这里在 Pastebin 上。

总体思路如下:

% Define new arc command
% Syntax: [draw options] (center) (initial angle:final angle:radius)
% https://tex.stackexchange.com/a/66220
\def\centerarc[#1](#2)(#3:#4:#5){%
    \draw [#1] ($(#2)+({#5*cos(#3)}, {#5*sin(#3)})$) arc (#3:#4:#5)%
}

\centerarc[tdplot_rotated_coords, canvas is yx plane at z=0.7, arrows = {latex}-{}](0, 0)(230 : 570 : 0.15)%
        node[anchor = north west, xshift = +2mm, yshift = -3mm, inner sep = \TikzInnerSep]%
            {1. $\psi$};

结果:

使用 TikZ 实现欧拉角(坐标变换)可视化 使用 TikZ 实现万向角(坐标变换)可视化

相关内容