2

I am using tikz-3dplot to draw vectors and arcs in 3d space. In the following example I am drawing two pictures. The code to draw the vector and the arc is the same in both pictures. However, picture 2 has customized axes:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz-3dplot}

\begin{document}
\tdplotsetmaincoords{60}{120}

% picture 1
\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=west]{$y$};
  \draw[thick,->] (0,0,0) -- ( 0,0,1) node[anchor=south]{$z$};  

  \draw[red,->] (0,0,0) -- (.5,.5,0);
  \draw[red,dotted] (.5,0,0) -- (.5,.5,0) -- (0,.5,0);

  \tdplotdefinepoints(0,0,0)(1,0,0)(0,1,0)
  \tdplotdrawpolytopearc[blue]{.7}{anchor=north,blue}{$\phi$}
\end{tikzpicture}

% picture 2
\begin{tikzpicture}[tdplot_main_coords,
  z={(\raarot cm, \rbarot cm)},
  y={(\rabrot cm, \rbbrot cm)},
  x={(\racrot, \rbcrot cm)}]

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

  \draw[red,->] (0,0,0) -- (.5,.5,0);
  \draw[red,dotted] (.5,0,0) -- (.5,.5,0) -- (0,.5,0);

  \tdplotdefinepoints(0,0,0)(1,0,0)(0,1,0)
  \tdplotdrawpolytopearc[blue]{.7}{anchor=north,blue}{$\phi$}
\end{tikzpicture}
\end{document}

picture 1

enter image description here

picture 2

enter image description here

In both pictures, the red vector is in the xy-plane, as expected. The problem is the blue arc in the second picture, I would expect it also to be in the xy-plane. What is going wrong here? Is my expectation wrong?

  • Related – sergej Sep 12 '15 at 18:18
  • It seems like when you specify x=... by yourself, tikz-3dplot does not take it seriously. It just uses the old coordinate system for \tdplotdrawpolytopearc. The really awkward thing is that you are trying to exchange x-axis and z-axis, which is mathematically not a rotation but a reflection. The package did not support reflection yet. – Symbol 1 Sep 13 '15 at 13:34
1

As I said in the comment: If you specify x=..., y=..., and z=... in TikZ layer by yourself, the draw commands such as

\draw[thick,->] (0,0,0) -- ( 1,0,0) node[anchor=south]{$x$};

is adapted to the new coordinate because points like (0,0,0) and (1,0,0) are evaluated by TikZ directly.

For tikz-3dplot's exclusive features such as \tdplotsetrotatedcoords, the new coordinate is calculated base on the variables \raarot and its friend. However never did tikz-3dplot know that \raarot is now used for horizontal component of z-unit vector. So tikz-3dplot will assume that \raarot is, as default, the horizontal of x-unit vector and ultimately gives the undesired result.

To come over this, just remember that the user should modify only \raarot and its friends and let tikz-3dplot do the remaining job, including applying x=.... In your case, you should begin your second picture as follows:

% picture 2

\let\raarotold\raarot \let\rbarotold\rbarot
\let\rabrotold\rabrot \let\rbbrotold\rbbrot
\let\racrotold\racrot \let\rbcrotold\rbcrot

\let\raarot\racrotold \let\rbarot\rbcrotold
\let\rabrot\rabrotold \let\rbbrot\rbbrotold
\let\racrot\raarotold \let\rbcrot\rbarotold

\begin{tikzpicture}[tdplot_main_coords]

This gives the desired result. (Except the anchor of \phi)

  • Would it be possible to change the "direction" of the z-axis? z shall be -z. – sergej Sep 25 '15 at 8:18
  • Sorry for even later reply. It is possible by changing the sign of some of the macros. I can show you. But you need to specify whether you need a "-z" label or an arrow pointing northeast. – Symbol 1 Oct 2 '15 at 8:07
  • The +z arrow should be pointing northeast. – sergej Oct 2 '15 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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