# how to get x,y and z components of a coordinate?

I would like to be able to use x, y and z components of a defined coordinate in TikZ to reuse the values somewhere else in my code. For example, let's have something like,

\coordinate (p1) at (-2.6,0.7,0);


I would like to do something like as below,

\coordinate (p11) at (p1_x,p1_y,12);


How can I do this?

• You can do this for x and y, but not for z. TikZ converts 3D coordinates to 2D at time of entry and does not remember the original data so cannot reconstruct it later. Mar 7, 2013 at 19:06
• Generally I found it easier to handle my own 3D projections via custom coordinate systems. In that way you retain much of the flexibility of TikZ which is not always obtainable in the regular 3D coordinate system. Mar 7, 2013 at 19:20
• Have a look at tex.stackexchange.com/q/54804/86 as I think it covers the same question. Mar 7, 2013 at 19:21
• Hi there! Thanks for your comments. So this seems to be a problem and I'd like to know what is the solution for? Any workaround? Mar 7, 2013 at 19:30
• See tex.stackexchange.com/a/98213/15925 for a proof of concept. Mar 8, 2013 at 9:46

Well, while a solution is impossible for the general case (for the reasons Andrew explained in a comment), a solution for this particular case is possible, via a horrible, horrible, hack.

The problem is that, as soon as you set something like:

\coordinate (p) at (3,4,5);


tikz computes the projection of the 3D point (3,4,5), according to the current values of keys x, y and z, and gets a 2D point, whose coordinates are stored in (p). So the final value for the coordinates stored in (p) are in absolute units (pt) and of course they are not 3 and 4.

But in this particular case, coordinate p1 has z=0:

\coordinate (p1) at (3,4,0);


so for this point the computed coordinates should be equal to the ones given, i.e: 3 and 4. But there is a problem, they are stored in absolute units (pt in this case). Tikz multiplies 3 (and 4) by the value of the key x (and y) which are 1cm by default, and the result expressed in pt is what (p1) gets. So, using let...in construct we can extract those values, but they will be in points.

So the horrible, horrible hack is to define x and y to be equal to 1pt, so that the figure uses points instead of cm as default units. This works:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{calc}

\begin{tikzpicture}[x=1pt, y=1pt, z=-0.5pt]  % Agh
% Let's draw some 3D axes
\coordinate (x) at (100,0,0);
\coordinate (y) at (0,100,0);
\coordinate (z) at (0,0,100);
\foreach \axis in {x,y,z}
\draw[-latex] (0,0,0) -- (\axis);

% Our point
\coordinate (p1) at (80, 30, 0);
% Compute the point at the same x,y, elevated 25pt in z
\path let \p1 = (p1)
in coordinate (p11) at (\x1, \y1, 25);

% Draw those points
\fill[red]     (p1) circle (1pt);
\fill[blue]   (p11) circle (1pt);
% Some bells and whistles
\draw[dotted] (p1) -- (p1|-x);
\draw[dotted] (p1) -- (p1-|y);
\draw[dashed,-latex] (p1) -- (p11);
\end{tikzpicture}


Results in: