[Tex/LaTex] Extract coordinates from 3D point


How do I extract coordinates from a three-dimensional point defined when using tikz-3dplot? I would like to perform some calculations on these (more specifically a cross-product of two vectors), but it seemed to be stumped on the \z1 coordinate (Undefined control sequence), as illustrated with the following example:

      \coordinate (A) at (1,2,3);
      \path let \p1=(A) in (\z1,\y1,\x1) coordinate (B);

Best Answer

When TikZ reads in a coordinate specification, it converts it straight-away to its internal standard form. This means that it does not remember anything about how that coordinate was specified. (The only time that I know of where this is not strictly true is with the end point of a to path where the end coordinate is passed as-is to the to path construction). In particular, when TikZ encounters a coordinate of the form (1,2,3) then it converts it there and then to 1*x-vector + 2*y-vector + 3*z-vector. When TikZ/PGF remembers a node's position, it remembers just the resulting. So what you are asking for is not possible with ordinary TikZ/PGF.

However, it is possible to define a new coordinate system that inserts a "save" step in the processing. When using a user-defined coordinate system, TikZ allows arbitrary code and the only requirement on that code is that it end with a declaration of what the internal representation of that point should be. It is, therefore, possible to save the input coordinate at this point and remember its 3D-ness. However, as this happens outside the normal flow of TikZ, the normal TikZ stuff can't use the extra information and so each piece that should use it has to be adapted so that it is 3D-aware. This is non-trivial!

At the TeX-SX Launchpad site, I have some preliminary code that is designed to do this. You can see some examples of this at https://tex.stackexchange.com/a/52627/86

Unfortunately, it certainly isn't advanced enough to work with the let syntax. So it wouldn't completely fit your requirements.