3

I want to draw a node exactly parallel to one of the three axes that are rotated. One solution could be to compute the axis angle relative to the horizontal line but I don't know what is the best way to do it by myself.

enter image description here

\documentclass[tikz,border=.5cm]{standalone}

\begin{document}
 \begin{tikzpicture}[rotate around y=-80,rotate around x=-100,rotate around z=-20]
       \begin{scope}[->]
      \draw(0,0,0)coordinate(O)--+(1,0,0)node[above]{\(x\)};
      \draw(O)--+(0,1,0)node[above]{\(y\)};
      \draw(O)--+(0,0,1)node[left]{\(z\)};
    \end{scope} 

    \node[draw,rectangle,
     rotate= 20, % 20 is not correct
    ] at(1cm,1cm){ \(\parallel x\) axis};

    \end{tikzpicture}   
\end{document}
Stefan Pinnow
  • 29,535

1 Answers1

3

There are two ways of reading your question, so this answer has two parts. The first picture makes use of the 3d library and the second one of calc. Note that, as of now, there is AFAIK no official documentation of the 3d library. On the other hand, the key canvas is xy plane at z=... etc. is sort of self-explaining.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{3d}
% small fix for canvas is xy plane at z % https://tex.stackexchange.com/a/48776/121799
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
    \def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
    \def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
    \def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
    \tikz@canvas@is@plane}
\makeatother
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[rotate around y=-80,rotate around x=-100,rotate around z=-20]
    \begin{scope}[->]
      \draw(0,0,0)coordinate(O)--+(1,0,0)node[above]{\(x\)};
      \draw(O)--+(0,1,0)node[above]{\(y\)};
      \draw(O)--+(0,0,1)node[left]{\(z\)};
    \end{scope} 
    \begin{scope}[canvas is xy plane at z=0,transform shape]
    \node[draw,rectangle,] at(1,1){ \(\parallel x\) axis};
    \end{scope}
    \begin{scope}[canvas is yz plane at x=0,transform shape]
    \node[draw,rectangle,] at(1,1){ \(\parallel y\) axis};
    \end{scope}
    \begin{scope}[canvas is zx plane at y=0,transform shape]
    \node[draw,rectangle,] at(1,1){ \(\parallel z\) axis};
    \end{scope}

    \end{tikzpicture}  
%   
    \begin{tikzpicture}[rotate around y=-80,rotate around x=-100,rotate around z=-20]
       \begin{scope}[->]
      \draw(0,0,0)coordinate(O)--+(1,0,0)node[above]{\(x\)};
      \draw(O)--+(0,1,0)node[above]{\(y\)};
      \draw(O)--+(0,0,1)node[left]{\(z\)};
    \end{scope} 
    \path let \p1=(1,0,0),\n1={atan2(\y1,\x1)} in 
    node[draw,rectangle,rotate=\n1+180] at(1cm,1cm){ \(\parallel x\) axis};
    \end{tikzpicture}   
\end{document} 

enter image description here