Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using tikz-3dplot and trying to represent navigation system transformations. In navigation systems, the orientation of the vehicle axis is given in terms of Roll, Pitch and Yaw. These are generally represented as Euler angles of Phi, Theta, and Psi.

I am trying to represent the following:

Rotate about the Z axis by Psi, the Yaw angle. Then, Rotate about the new Y axis by the pitch angle (Theta). Then, Rotate about the new X axis the roll angle (Phi).

The challenge I am having is that Tikz-3dplot rotates about the Z, Y then Z axis. According to the documentation, these rotations should be relative to the "world" Z, Y, and Z axes. After reading up on Euler angles (on Wikipedia), I was educated to the fact that there are actually multiple representations of the Euler angles, and the Z,Y,Z is one, as is the Z,Y,X that I was familiar with.

The problem I have now is that it appears that when I apply the tikz-3dplot command: \tdplotsetrotatedcoords{\psi}{\theta}{\phi} that the first rotation is about the Z axis, as expected. The second rotation (\theta), is about the ROTATED Y axis, which is really what I want, but NOT what the documentation claims. Unfortunately, here is where I am stuck. The final rotation, which needs to be about the rotated X axis, in fact rotates about the ROTATED Z axis...

If the rotations were about the world axes, I could come up with a transform (although I would really have to think about it).. but, since they are not, I am completely stumped as to how to get that final rotated system...

I have been doing a lot of searching for answers.. and come up with very little. I've even tried to modify the tikz-3dplot package, making a copy of my own.. this might work, but I am hoping there is a better answer, as I really don't have time to learn enough about tex to do this.. nor the time to troubleshoot it.


Keywords to make more discoverable in search engines:

z-y-z sequence, z-y-x sequence, rotation sequence

share|improve this question
    
If Jakes answer solved your problem, please accept it by clicking the checkmark to the left, thereby marking the question as "solved" and awarding some points to both Jake and yourself. –  Torbjørn T. Dec 2 '11 at 10:18
    
Ed, can you please mark this as solved? Thanks. –  Ingo Apr 18 '13 at 11:05
add comment

1 Answer

Here's a macro \tdseteulerxyz that sets the Euler matrix to use an XYZ (yaw-pitch-roll) order for the rotations. The matrix is taken from Wikipedia, where you can also find the matrices for the other rotation orders. Note that this is the reverse of how tikz-3dplot normally uses its arguments to \tdplotsetrotatedcoords; the first argument is roll and the last is yaw.

Here are two tikz-3dplot pictures that are identical except for the fact that \tdseteulerxyz was called just before the second picture.

And here's the code:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

\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}
}
}

\tdplotsetmaincoords{60}{110}
\tdseteulerxyz
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\tdplotsetrotatedcoords{30}{30}{30}
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(.7,0,0) node[anchor=north]{$x'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,.7,0) node[anchor=west]{$y'$};
\draw[thick,color=blue,tdplot_rotated_coords,->] (0,0,0) --
(0,0,.7) node[anchor=south]{$z'$};
\end{tikzpicture}

\end{document}
share|improve this answer
1  
Jake, you just saved my day. Many thanks. –  Ingo Oct 29 '12 at 12:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.