# TikZ: Define 3D coordinate axes for the space pyramid (tetrahedron)

How can I specify such coordinate axes? So then, e.g. A(0,0,0) or C(a, a, 0).

What is the angle between the x and y axes? Yes, I am frankly just wondering. Probably not simply 30 °; it is something like 26.5 °.
Is there a certain standard?

I have the expression measured AB = 12.8cm, AC = 12.5cm - maybe both should be exactly the same length (?).

Note: I am primarily interested in how to set the coordinate axes correctly (unlike packages like tkzeuclide or tikz-3d).

I can get the shown representation approximately with
z={(0,1)}, y={({0.9*cos(10)},{0.9*sin(10)})}, x={({cos(16.5)},{-sin(16.5)})}

But I do not quite understand these: 'z = ...' has to come before y and x. I do not know why.

The task is not so much to draw a tetrahedron. I can do that already, if I have the coordinate system together.

\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[%scale=0.7,
z={(0,1)},
y={({0.9*cos(10)},{0.9*sin(10)})},
x={({cos(16.5)},{-sin(16.5)})}
]

\begin{scope}[-latex]
\foreach \P/\s/\Pos in {(1,0,0)/x/below, (0,1,0)/y/left, (0,0,2)/z/right}
\draw[] (0,0,0) -- \P node[\Pos, pos=0.9,inner sep=2pt]{$\s$};
\end{scope}

\end{tikzpicture}

\end{document}

• What do you mean by "unlike packages like ... tikz-3d"? If you mean tikz-3dplot, this one does not set anything incorrectly. Rather, it does orthonormal projections. And you can use it as a basis for something that allows you to introduce coordinate systems of the sort you want (but I do not quite see the point of that). And no, if two distances in 3d are the same, their projections are in general different. – user121799 Jul 5 '19 at 16:06
• I want to know: How to set "={({<...>},{<..>})}" correctly for x,y,z. – cis Jul 5 '19 at 16:09

tikz-3dplot does set the coordinate correctly. Why does the output depend on whether you set z first or last? This is because if you say z={(0,1)}, then the z vector will be given by z=0*x+1*y=y, where x and y are the unit vectors in x and y directions, respectively. So if you set z before setting x and y, you will get z=y_old, but if you set it afterwards you will get z=y_new. This is all explained in this great answer, where it is also explained that the results are very different for vectors in which the components have units. (Of course you can also have hybrids.) Then the order does not matter, a vector with units (a cm, b cm) will always be a cm in the horizontal direction and b cm in the vertical direction. This is possibly the reason why tikz-3dplot sets the vectors with units.

Their components are functions of the view angles. They are the columns of an SO(3) matrix, as they should.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{100}
\begin{tikzpicture}[line join=round,tdplot_main_coords,declare function={a=5;}]
\begin{scope}[canvas is xy plane at z=0,transform shape]
\path foreach \X [count=\Y] in {A,B,C}
{(\Y*120:{a/(2*cos(30))}) coordinate(\X)};
\end{scope}
\path (0,0,{a*cos(30)}) coordinate (D);
\draw foreach \X/\Y [remember=\X as \Z (initially D)] in {A/B,B/C,C/D,D/A}
{(\X) -- (\Z) -- (\Y)};
\end{tikzpicture}
\end{document}


Note that I am not claiming that this is a regular polyhedron.

• That's nice, good and right; but it is not the desired representation. I can get these approximately with z={(0,1)}, y={({0.9*cos(10)},{0.9*sin(10)})}, x={({cos(16.5)},{-sin(16.5)})} But I do not quite understand these: 'z = ...' has to come before y and x. I do not know why. As I said, the task was not so much to draw a tetrahedron. I can do that already, if I have the coordinate system together. – cis Jul 5 '19 at 19:49
• @cis This is because if you add the z last, then it will have components (0,1) in terms of the new coordinates, i.e. z=0*x_new+1*y_new=y_new. On the other hand, if you set it first it will be z=y_old, which points upwards on the screen. – user121799 Jul 5 '19 at 20:24
• Ah, I understand. – cis Jul 5 '19 at 20:55
• @cis I believe that this is the reason why tikz-3dplot adds units to its basis vectors. If you would say z=(0cm,1cm) it would always point upwards, regardless when you set it. OK, this is your question then? I misread it. (+1) Anyway, the answer is this and the above comment. You may also want to look at tex.stackexchange.com/a/31606/121799, where the difference between basis vectors with or without units is explained very nicely. – user121799 Jul 5 '19 at 21:37
• @marmot Four vertices of regular tetrahedron coordinate(A) at (\a,\a,\a) coordinate (B) at (\a,-\a,-\a) coordinate (C) at (-\a,\a,-\a) coordinate (D) at (-\a,-\a,\a) – minhthien_2016 Jul 10 '19 at 3:02