2

I'm a bit confused by the following code. I would think that the following would produce an animation of rotating 90-degrees around the x-, y-, and z-axes, but the first part of the animation looks like it rotates around the z-axis and not the x-axis. Any ideas?

\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{animate}  % Animations
\usepackage{tikz-3dplot}

\usepgflibrary{arrows}
\usetikzlibrary{decorations.markings, arrows, decorations.pathmorphing,
   backgrounds, positioning, fit, shapes.geometric}

\def\drawaxes{
    \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
    \draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=south]{$z$};
}

\begin{document}
\begin{frame}
  \begin{center}
    \begin{animateinline}[autoplay, controls, poster=first]{60}
      \multiframe{90}{iFrame=0+1}{
        \tdplotsetmaincoords{0}{0}
        \begin{tikzpicture}[tdplot_main_coords]
          \draw (-5cm, -3cm) rectangle (5cm, 3cm);

          \tdplotsetrotatedcoords{\iFrame}{0}{0}
          \begin{scope}[color=red,
                        tdplot_rotated_coords,
                        xshift=-3cm,scale=0.25]
            \drawaxes
          \end{scope}

          \tdplotsetrotatedcoords{0}{\iFrame}{0}
          \begin{scope}[color=red,tdplot_rotated_coords,scale=0.25]
            \drawaxes
          \end{scope}

          \tdplotsetrotatedcoords{0}{0}{\iFrame}
          \begin{scope}[color=red,
                        tdplot_rotated_coords,
                        xshift=3cm,scale=0.25]
            \drawaxes
          \end{scope}
        \end{tikzpicture}
      }
    \end{animateinline}
  \end{center}
\end{frame}
\end{document}
2
  • I certainly I have not much experience with tikz but have you tried to add % at the end of \multiframe{90}{iFrame=0+1}{% .... because I think that something confuse the compiler
    – karathan
    Commented Apr 1, 2013 at 20:39
  • Thanks for the suggestion, but the % didn't change anything.
    – cjohnson
    Commented Apr 1, 2013 at 20:48

2 Answers 2

3

The problem you're are stating is because of the convention adopted by Jeff Hein in the tikz-3dplot.

As he explained, he chose the Euler z-y-z convention (I guess it's the most widely used convention in astrophysics).

Syntax: \tdplotsetrotatedcoords{α}{β }{γ }

Parameters: α The angle (in degrees) through which the rotated frame is rotated about the world z axis. β The angle (in degrees) through which the rotated frame is rotated about the world y axis. γ The angle (in degrees) through which the rotated frame is rotated about the world z axis.

You want to do rotations around z, y and x axis witch are usually called nautical angles (or Tait-Bryan, or Cardan, or zyx Euler angles...).

A good solution to changed the convension used is to redefine the rotation matrix used by \tdplotsetrotatedcoords as suggested in Navigation system coordinates in tikz-3dplot .

2

Here's a work-around in case anyone else runs into the same problem. Use \tdplotsetmaincoords{rotationX}{0}, plot the rotation, then switch back to \tdplotsetmaincoords{0}{0} to plot as normal. For example, in the code I posted above, replace

      \tdplotsetrotatedcoords{0}{\iFrame}{0}
      \begin{scope}[color=red,tdplot_rotated_coords,scale=0.25]
        \drawaxes
      \end{scope}

with

      \tdplotsetmaincoords{\iFrame}{0}
      \begin{scope}[color=red,tdplot_main_coords,scale=0.25]
        \drawaxes
      \end{scope}
      \tdplotsetmaincoords{0}{0}

It may not be the most elegant solution, but it seems to have done the trick for the animation I was trying to make.

1
  • be careful, not all of your rotations are in the positive way. tdplotsetrotatedcoords and tdplotmaincoords work in opposite ways.
    – Vser
    Commented Jul 18, 2013 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .