Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass{article}
  \usepackage{tikz}
  \usetikzlibrary{calc}
  \usepackage{tikz-3dplot}
\begin{document}
  \begin{figure}
    \tdplotsetmaincoords{0}{0}
    \begin{tikzpicture}[tdplot_main_coords]
      \coordinate (A) at (1,2,3);
      \path let \p1=(A) in (\z1,\y1,\x1) coordinate (B);
    \end{tikzpicture}
  \end{figure}
\end{document}
share|improve this question
    
The coordinates you extract using the let syntax are two-dimensional canvas coordinates, not the logical three-dimensional ones, unfortunately. –  Jake May 7 '12 at 16:50
1  
@Jake: I am not bound to using \path let; if there is any other ways to extract the logical coordinates (so that they can be used in e.g. \pgfmathresult), I am open for that, too. –  RolKau May 7 '12 at 16:52
    
This is not directly possible. TikZ converts coordinates to 2D at the time they are processed and then forgets how they were specified. So (A) refers to the 2D point that (1,2,3) transforms to. I have developed some code that allows TikZ to remember 3D coordinate information. It is available on the TeX-SX launchpad page (bazaar.launchpad.net/~tex-sx/tex-sx/development/files). Might that be of some help? It was used in answering another question here: tex.stackexchange.com/a/52627/86 where you can see some examples. –  Loop Space May 19 '12 at 18:17
    
@AndrewStacey Perhaps make your comment an answer? –  Joseph Wright Aug 6 '12 at 10:18

1 Answer 1

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 http://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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.