TikZ中的Z向量

TikZ中的Z向量

在 TikZ 中使用 3D 坐标时,有没有办法改变 Z 向量的方向,使其不指向 XY 平面的 45 度角?给定一个如下所示的立方体绘图,我想要一种很好的方法来移动背面的面,而无需调整坐标。

\begin{tikzpicture}
\draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
\draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
\draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1); \draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1); 
\end{tikzpicture}

查看手册,我只能找到改变 Z 向量长度的能力,而不能找到改变其方向的能力。

答案1

您可以使用 键指定 z 方向的单位向量z,使 z 向量以给定角度出现在 XY 平面中。

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[z={(60:0.5cm)}]
    \draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
    \draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
    \draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1); \draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\end{tikzpicture}

\begin{tikzpicture}[z={(3cm,1.5cm)}]
    \draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
    \draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
    \draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1); \draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\end{tikzpicture}
\end{document}

输出

答案2

您可以使用rotate around y=<angle>。同样有rotate around x=<angle>rotate around z=<angle>

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
\draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
\draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
\draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1);
\draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\draw[red] (0,0,0) -- (0,0,2)node {$z$};
\end{tikzpicture}
  \begin{tikzpicture}[rotate around y=45]
\draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
\draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
\draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1); 
\draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\draw[red] (0,0,0) -- (0,0,2)node {$z$};
\end{tikzpicture}
  \begin{tikzpicture}[rotate around x=45]
\draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
\draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
\draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1);
\draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\draw[red] (0,0,0) -- (0,0,2)node {$z$};
\end{tikzpicture}
  \begin{tikzpicture}[rotate around z=5]
\draw (0,0,0) -- (1,0,0) -- (1,1,0) -- (0,1,0) -- cycle;
\draw (0,0,1) -- (1,0,1) -- (1,1,1) -- (0,1,1) -- cycle;
\draw (0,0,0) -- (0,0,1); \draw (1,0,0) -- (1,0,1);
\draw (0,1,0) -- (0,1,1); \draw (1,1,0) -- (1,1,1);
\draw[red] (0,0,0) -- (0,0,2)node {$z$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容