![如何实现并绘制具有欧拉角的框架的最终旋转。](https://linux22.com/image/310118/%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%B9%B6%E7%BB%98%E5%88%B6%E5%85%B7%E6%9C%89%E6%AC%A7%E6%8B%89%E8%A7%92%E7%9A%84%E6%A1%86%E6%9E%B6%E7%9A%84%E6%9C%80%E7%BB%88%E6%97%8B%E8%BD%AC%E3%80%82.png)
我想使用欧拉角进行最终旋转。在此链接中欧拉角,最终的旋转经历了三次连续的旋转,从帧 (x,y,z) 开始,经过 (x',y',z'),然后是 (x'',y'',z''),最后以帧 (x''',y''',z''') 结束。我见过这个邮政这在某种程度上帮助了我。在我的例子中,第一次旋转产生了
第二次旋转产生
现在第三次旋转并没有产生上述链接中的结果。
x2,x3应该指向同一方向。
这是代码
\documentclass[preview,varwidth ,multi,border=3pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1cm}
\begin{document}
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
% main Frame (x,y,z)
\draw[thick,->,line width=0.55mm] (O) -- (2.0,0,0) node[anchor=north west]{$X$};
\draw[thick,->,line width=0.55mm] (O) -- (0,2.0,0) node[anchor=west] {$Y$};
\draw[thick,->,line width=0.55mm] (O) -- (0,0,2.0) node[anchor=south] {$Z$};
% define yaw, pitch, and roll
\def \yaw {30}
\def \roll {30}
\def \pitch {30}
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Yaw )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First rotation yields Frame 1 (about z axis main)
% Frame 1 (x1,y1, z1)
\tdplotsetrotatedcoords{\yaw}{0}{0}
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (1.5,0,0) node[xshift=0mm,anchor=north west] {$x^{1}$};
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (0,1.5,0) node[anchor=west]{$y^{1}$};
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (0,0,1.5) node[anchor=south,xshift=3mm, yshift=-1mm]{$z^{1}$};
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Pitch )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Second rotation yields Frame 2 (about y1 axis)
% Frame 2 (x2,y2, z2)
\tdplotsetrotatedcoords{\yaw}{\pitch}{0}
\draw[thick,->,line width=0.65mm, color=blue, tdplot_rotated_coords]
(O) -- (1.0,0,0) node[xshift=0mm,anchor=north west]{$x^{2}$};
\draw[thick,->,line width=0.65mm, color=blue,tdplot_rotated_coords]
(O) -- (0,1.0,0) node[anchor=west]{$y^{2}$};
\draw[thick,->,line width=0.65mm, color=blue,tdplot_rotated_coords]
(O) -- (0,0,1.0) node[anchor=south,xshift=3mm, yshift=-1mm]{$z^{2}$};
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Roll )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Third rotation yields Frame 3 (about x2 axis) <-- (it should be )
% Frame 3 (x3,y3,z3)
\tdplotsetrotatedcoords{\yaw}{\pitch}{\roll}
\draw[thick,->,line width=0.65mm, color=green, tdplot_rotated_coords]
(O) -- (0.5,0,0) node[xshift=0mm,anchor=north west]{$x^{3}$};
\draw[thick,->,line width=0.65mm, color=green,tdplot_rotated_coords]
(O) -- (0,0.5,0) node[anchor=west]{$y^{3}$};
\draw[thick,->,line width=0.65mm, color=green,tdplot_rotated_coords]
(O) -- (0,0,.5) node[anchor=south]{$z^{3}$};
\end{tikzpicture}
\end{document}
答案1
我认为这可能是重复的tikz-3dplot 中的导航系统坐标:默认情况下,tikz-3dplot
使用旋转序列 ZYZ(即先绕 Z 轴旋转,然后绕新的 Y 轴 Y',再绕新的 Z 轴 Z''),而您需要旋转序列 ZYX。为此,您必须重新定义变换参数:
\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}
}
}
然后您可以使用 激活新的旋转序列\tdseteulerxyz
。
完整代码如下:
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\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}
}
}
\begin{document}
\tdseteulerxyz
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
% main Frame (x,y,z)
\draw[thick,->,line width=0.55mm] (O) -- (2.0,0,0) node[anchor=north west]{$X$};
\draw[thick,->,line width=0.55mm] (O) -- (0,2.0,0) node[anchor=west] {$Y$};
\draw[thick,->,line width=0.55mm] (O) -- (0,0,2.0) node[anchor=south] {$Z$};
% define yaw, pitch, and roll
\def \yaw {30}
\def \roll {30}
\def \pitch {30}
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Yaw )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First rotation yields Frame 1 (about z axis main)
% Frame 1 (x1,y1, z1)
\tdplotsetrotatedcoords{\yaw}{0}{0}
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (1.5,0,0) node[xshift=0mm,anchor=north west] {$x^{1}$};
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (0,1.5,0) node[anchor=west]{$y^{1}$};
\draw[thick,->,line width=0.65mm, color=red, tdplot_rotated_coords]
(O) -- (0,0,1.5) node[anchor=south,xshift=3mm, yshift=-1mm]{$z^{1}$};
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Pitch )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Second rotation yields Frame 2 (about y1 axis)
% Frame 2 (x2,y2, z2)
\tdplotsetrotatedcoords{\yaw}{\pitch}{0}
\draw[thick,->,line width=0.65mm, color=blue, tdplot_rotated_coords]
(O) -- (1.0,0,0) node[xshift=0mm,anchor=north west]{$x^{2}$};
\draw[thick,->,line width=0.65mm, color=blue,tdplot_rotated_coords]
(O) -- (0,1.0,0) node[anchor=west]{$y^{2}$};
\draw[thick,->,line width=0.65mm, color=blue,tdplot_rotated_coords]
(O) -- (0,0,1.0) node[anchor=south,xshift=3mm, yshift=-1mm]{$z^{2}$};
%_____________________________________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%( Roll )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Third rotation yields Frame 3 (about x2 axis) <-- (it should be )
% Frame 3 (x3,y3,z3)
\tdplotsetrotatedcoords{\yaw}{\pitch}{\roll}
\draw[thick,->,line width=0.65mm, color=green, tdplot_rotated_coords]
(O) -- (0.5,0,0) node[xshift=0mm,anchor=north west]{$x^{3}$};
\draw[thick,->,line width=0.65mm, color=green,tdplot_rotated_coords]
(O) -- (0,0.5,0) node[anchor=west]{$y^{3}$};
\draw[thick,->,line width=0.65mm, color=green,tdplot_rotated_coords]
(O) -- (0,0,.5) node[anchor=south]{$z^{3}$};
\end{tikzpicture}
\end{document}