# Changing axes in tikz-3dplot picture

As is, the axes in the following picture

\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\begin{tikzpicture}[scale=3]
\draw[thick,->,black] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north east]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=east]{$z$};
\end{tikzpicture}
\end{document}


are as follows:

• x-axis: to the right
• y-axis: up
• z-axis: towards you

What do I need to do to achieve the following:

• x-axis: towards you
• y-axis: to the right
• z-axis: up

It goes without saying that any coordinates entered must observe the changed axes.

-
Can you express this axis change as a rotation somehow? If you can figure out the Euler rotation angles for the transformation, it's easy to add that in tikz-3dplot. –  Mikael Vejdemo-Johansson Apr 16 '11 at 16:57
I think it's a 90-degree rotation about the x-axis, followed by one about the z-axis, or about the z-axis followed by the y-axis –  Brent.Longborough Apr 16 '11 at 17:38

Try the coordinate matrix transformation option cm=....

\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\begin{tikzpicture}[scale=3]
\draw[thick,->,black] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north east]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=east]{$z$};
\end{tikzpicture}
\begin{tikzpicture}[scale=3,cm={-1,-1,1,0,(0,0)},x=3.85mm,z=-1cm]
\draw[thick,->,black] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=north east]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=east]{$z$};
\end{tikzpicture}
\end{document}


Edit: TikZ provides a coordinate transformation matrix cm = (a,b;c,d) that can be used to transform the coordinates (x,y) into a new set of coordinates (X,Y) = (a,b;c,d)*(x,y) = (ax+by;cx+dy). In the OP's case we want the direction of X to be 'towards you', i.e. X = -x - y. The Y coordinate must be 'to the right', i.e. Y = x. Solving for a, b, c and d we find a = -1, b = -1, c = 1 d = 0 This is what is given in the option cm={a,b,c,d,(0,0)} where (0,0) is the x- and y-shift of the origo. The new Z coordinate is Z = X + Y = -y.

Before being plotted, the coordinates are multiplied with the TikZ unit vectors. Default is x=1cm, y=1cm and z=-3.85mm. Thus to get the same length and direction of the axis in the new orientation we need to change this to x=3.85mm, y=1cm and z=-1cm. As y=1cm is the default this is left out.

I am not sure the above is clear... Feel free to improve the explanation.

-
I took a look at the manual on cm=, and my brain now hurts. Would you care to add some comments on your use of cm= in this instance, plus an explanation of x= and z=? That would transform your answer from an example into a learning opportunity! Thanks in advance (+1) –  Brent.Longborough Apr 16 '11 at 21:29
@Brent.Longborough: I have tried to explain the transformation. There are two steps: rotate the (x,y) plane using the cm matrix and then change the TikZ unit vectors using x= and z= options. –  Martin Heller Apr 16 '11 at 23:08
Thank you very much. That clarifies it considerably. –  Brent.Longborough Apr 17 '11 at 1:18
Perfect! Thank you very much! (I love this website: you ask your question, you go to bed, when you wake up in the morning your problem has been solved by the (TeX)powers that be :-) I wish the rest of the world worked this way too ... –  Harry Apr 17 '11 at 8:30

In fact all you have to do is change the first 2 lines:

Default axis orientation is as you have stated.

So:

\tdplotsetmaincoords{60}{105} % rotate 60 degrees around x axis, then 105 degrees about z
\begin{tikzpicture}[tdplot_main_coords]


The command from the manual is as follows (see also this example)

Syntax: \tdplotsetmaincoords{ theta }{ phi }

Parameters:

• theta: The angle (in degrees) through which the coordinate frame is rotated about the x axis.
• phi: The angle (in degrees) through which the coordinate frame is rotated about the z axis.

-