Advertisement
Guest User

Drawing Euler angle unit axis roations with LaTeX and TikZ

a guest
Jun 7th, 2013
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 5.52 KB | None | 0 0
  1. \documentclass[landscape]{article}
  2.  
  3. \usepackage{wasysym}
  4. \usepackage{tikz}
  5. \usepackage{tikz-3dplot}
  6. \usepackage{pgfplots}
  7.    % Workaround for making use of externalization possible
  8.    % -> remove hardcoded pdflatex and replace by lualatex
  9.    \usepgfplotslibrary{external}
  10.        \tikzset{external/system call={lualatex \tikzexternalcheckshellescape%
  11.         -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
  12.  
  13. % Redefine rotation sequence for tikz3d-plot to z-y-x
  14. \newcommand{\tdseteulerxyz}{
  15. \renewcommand{\tdplotcalctransformrotmain}{%
  16. %perform some trig for the Euler transformation
  17. \tdplotsinandcos{\sinalpha}{\cosalpha}{\tdplotalpha}
  18. \tdplotsinandcos{\sinbeta}{\cosbeta}{\tdplotbeta}
  19. \tdplotsinandcos{\singamma}{\cosgamma}{\tdplotgamma}
  20. %
  21. \tdplotmult{\sasb}{\sinalpha}{\sinbeta}
  22. \tdplotmult{\sasg}{\sinalpha}{\singamma}
  23. \tdplotmult{\sasbsg}{\sasb}{\singamma}
  24. %
  25. \tdplotmult{\sacb}{\sinalpha}{\cosbeta}
  26. \tdplotmult{\sacg}{\sinalpha}{\cosgamma}
  27. \tdplotmult{\sasbcg}{\sasb}{\cosgamma}
  28. %
  29. \tdplotmult{\casb}{\cosalpha}{\sinbeta}
  30. \tdplotmult{\cacb}{\cosalpha}{\cosbeta}
  31. \tdplotmult{\cacg}{\cosalpha}{\cosgamma}
  32. \tdplotmult{\casg}{\cosalpha}{\singamma}
  33. %
  34. \tdplotmult{\cbsg}{\cosbeta}{\singamma}
  35. \tdplotmult{\cbcg}{\cosbeta}{\cosgamma}
  36. %
  37. \tdplotmult{\casbsg}{\casb}{\singamma}
  38. \tdplotmult{\casbcg}{\casb}{\cosgamma}
  39. %
  40. %determine rotation matrix elements for Euler transformation
  41. \pgfmathsetmacro{\raaeul}{\cacb}
  42. \pgfmathsetmacro{\rabeul}{\casbsg - \sacg}
  43. \pgfmathsetmacro{\raceul}{\sasg + \casbcg}
  44. \pgfmathsetmacro{\rbaeul}{\sacb}
  45. \pgfmathsetmacro{\rbbeul}{\sasbsg + \cacg}
  46. \pgfmathsetmacro{\rbceul}{\sasbcg - \casg}
  47. \pgfmathsetmacro{\rcaeul}{-\sinbeta}
  48. \pgfmathsetmacro{\rcbeul}{\cbsg}
  49. \pgfmathsetmacro{\rcceul}{\cbcg}
  50. }
  51. }
  52.  
  53. \tdseteulerxyz
  54.  
  55. \usepackage{siunitx}
  56.  
  57.  
  58. %%%%%%%%% Z
  59. \begin{document}
  60. % Set the plot display orientation
  61. % Syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
  62. \tdplotsetmaincoords{60}{140}
  63.  
  64. \pgfmathsetmacro{\zRot}{10}
  65. \pgfmathsetmacro{\yRot}{10}
  66. \pgfmathsetmacro{\xRot}{10}
  67.  
  68. % Start tikz picture, and use the tdplot_main_coords style to implement the display
  69. % coordinate transformation provided by 3dplot.
  70. \begin{tikzpicture}[scale=2,tdplot_main_coords]
  71.  
  72. % Set origin of main (body) coordinate system
  73. \coordinate (O) at (0,0,0);
  74.  
  75. % Draw main coordinate system
  76. \draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
  77. \draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
  78. \draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$,
  79.    \textcolor{blue}{$z'$}};
  80.  
  81. % Intermediate frame 1
  82. \tdplotsetrotatedcoords{\zRot}{0}{0}
  83. \draw[thick,tdplot_rotated_coords,->, blue] (0,0,0) -- (1,0,0) node[anchor=north east]{$x'$};
  84. \draw[thick,tdplot_rotated_coords,->, blue] (0,0,0) -- (0,1,0) node[anchor=west]{$y'$};
  85. \draw[thick,tdplot_rotated_coords,->, blue] (0,0,0) -- (0,0,1) node[anchor=west]{};
  86.  
  87. \end{tikzpicture}
  88. %%%%%%%%%%%%%%%%% Z-Y
  89. \begin{tikzpicture}[scale=2,tdplot_main_coords,font=\small]
  90.         thick,
  91. % Set origin of main (body) coordinate system
  92. \coordinate (O) at (0,0,0);
  93.  
  94. % Draw main coordinate system
  95. \draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
  96. \draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
  97. \draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};
  98.  
  99. % Intermediate frame 1
  100. \tdplotsetrotatedcoords{\zRot}{0}{0}
  101. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (1,0,0) node[anchor=north east]{$x'$};
  102. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,1,0) node[anchor=west]{};
  103. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,0,1) node[anchor=west]{$z'$};
  104.  
  105. % Intermediate frame 2
  106. \tdplotsetrotatedcoords{\zRot}{\yRot}{0}
  107. \draw[thick,tdplot_rotated_coords,->, green] (0,0,0) -- (1,0,0)
  108. node[anchor=north ]{$x''$};
  109. \draw[thick,tdplot_rotated_coords,->, green] (0,0,0) -- (0,1,0)
  110. node[anchor=west]{$y''$, \textcolor{blue}{$y'$}};
  111. \draw[thick,tdplot_rotated_coords,->, green] (0,0,0) -- (0,0,1)
  112. node[anchor=east]{$z''$};
  113.  
  114. \end{tikzpicture}
  115. %%%%%%%%%%%%% Z-Y-X
  116. \begin{tikzpicture}[scale=2.5,tdplot_main_coords]
  117.  
  118. % Set origin of main (body) coordinate system
  119. \coordinate (O) at (0,0,0);
  120.  
  121. % Draw main coordinate system
  122. \draw[red, ,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x_{\mathcal{I}}$};
  123. \draw[red, ,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y_{\mathcal{I}}$};
  124. \draw[red, ,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{I}}$};
  125.  
  126. % Intermediate frame 1
  127. \tdplotsetrotatedcoords{\zRot}{0}{0}
  128. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (1,0,0) node[anchor=north east]{$x'$};
  129. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,1,0) node[anchor=west]{$y'$};
  130. \draw[tdplot_rotated_coords,->, blue] (0,0,0) -- (0,0,1) node[anchor=west]{$z'$};
  131.  
  132. % Intermediate frame 2
  133. \tdplotsetrotatedcoords{\zRot}{\yRot}{0}
  134. \draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (1,0,0) node[anchor=
  135. north]{};
  136. \draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,1,0)
  137. node[anchor=west]{$y''$};
  138. \draw[,tdplot_rotated_coords,->, green] (0,0,0) -- (0,0,1)
  139. node[anchor=south]{$z''$};
  140.  
  141. % Rotate to final frame
  142. \tdplotsetrotatedcoords{\zRot}{\yRot}{\xRot}
  143. \draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (1,0,0)
  144. node[anchor=west]{$x_{\mathcal{B}}$, \textcolor{green}{$x''$}};
  145. \draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,1,0) node[anchor=west]{$y_{\mathcal{B}}$};
  146. \draw[thick,tdplot_rotated_coords,->, cyan] (0,0,0) -- (0,0,1) node[anchor=south]{$z_{\mathcal{B}}$};
  147.  
  148. \end{tikzpicture}
  149.  
  150. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement