在旋转的三维图片中绘制与 x、y 或 z 轴平行的节点

在旋转的三维图片中绘制与 x、y 或 z 轴平行的节点

我想绘制一个与三个旋转轴之一完全平行的节点。一种解决方案可能是计算相对于水平线的轴角,但我不知道自己最好的方法是什么。

在此处输入图片描述

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

答案1

有两种方法可以解读您的问题,因此这个答案分为两部分。第一张图片使用了库3d,第二张图片使用了calc。请注意,到目前为止,据我所知,没有该3d库的官方文档。另一方面,密钥canvas is xy plane at z=...等有点不言自明。

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

在此处输入图片描述

相关内容