# Z vector in TikZ

When using 3D coordinates in TikZ, is there a way of changing the direction of the Z vector so that it doesn't point at a 45 degree angle in the X-Y plane? Given a drawing of a cube like the following, I would like a nice way to shift the face at the back around without having to tweak the coordinates.

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


Looking at the manual, I was only able to find the ability to change the length of the Z vector, not its direction.

-

You can specify the unit vector for the z-direction with the z key, making the z-vector appear at a given angle in the XY-plane.

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


-
Aha - this is exactly what I needed. Where I was going wrong was by not putting the coordinate in "z={(3cm,1.5cm)}" in braces. Thanks. – Ashley Montanaro May 9 '14 at 14:18

You can use rotate around y=<angle>. Similarly there is rotate around x=<angle> and 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}


-
Thanks, this is helpful but for my application setting the vector directly as described by the other answer turns out to be more useful. – Ashley Montanaro May 9 '14 at 14:19