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.

I am trying to position a node in 3D according to the (x, y) coordinates of a node previously defined on another z level. However, I can't figure out how to make it work:

\documentclass{article}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[pdftex, active, tightpage]{preview}
\usetikzlibrary{calc, 3d, backgrounds, positioning}
\setlength\PreviewBorder{2mm}
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{preview}
\begin{tikzpicture}[scale = 1, x  = {(-0.2cm, -0.5cm)},
    y  = {(0.9659cm, -0.05882cm)},
    z  = {(0cm, 1cm)}]
    \begin{scope}[canvas is yx plane at z = 0]
        \draw (2, 3) node[inner sep = 0pt, outer sep = 0pt, color = black!60, circle, minimum size = 0.2pt] (1) {};
        \draw (3, 3) node[inner sep = 0pt, outer sep = 0pt, color = black!60, circle, minimum size = 0.2pt] (2) {};
        \draw (3, 2) node[inner sep = 0pt, outer sep = 0pt, color = black!60, circle, minimum size = 0.2pt] (3) {};
        \draw (1.center) -- (2.center) -- (3.center) -- cycle;
    \end{scope}
    \begin{scope}[canvas is yx plane at z = 1.5]
        \draw (2, 3) node[inner sep = 0pt, outer sep = 0pt, color = red!60, circle, fill, text width = 0.2pt] {};
        \draw node[inner sep = 0pt, outer sep = 0pt, color = blue!60, circle, fill, text width = 0.2pt] at (1) {};
    \end{scope}
\end{tikzpicture}
\end{preview}
\end{document}

The red node is where he is supposed to be, with the explicit (x, y) coordinates (just ''above'' the first node), but the blue node is at z = 0

What is an efficient way to make this work, i.e. to have the blue node cover the red node ? (is it possible to avoid using the second scope and just use at (1) ++ some magic relative displacement in 3D here or even some hidden(*) zshift parameter ?)

(*) I couldn't find this in the manual

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

I'm not sure I understand your code. I made some modifications but if I going in the wrong direction, I will update my answer.

Firstly minimum size = 0.2pt is not large enough to see a circle. The line width is by default 0.4 pt, if you want to see the nodes you need to increase the width! Then you can avoid some repetition and use styles for the nodes. When you create the second scope, if you use (2,3) to place a node, you use the canvas and the node is correctly placed. However, when you want to place the blue one at (1), you place the node at coordinates defined (1), which is defined outside this scope, so the coordinates of (1) don't change!

I don't understand text width = 0.2pt in your code. Is it a mistake?

Here is perhaps the simplest code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, 3d, backgrounds, positioning}
\begin{document}

\begin{tikzpicture}[scale = 1, 
    x  = {(-0.2cm, -0.5cm)},
    y  = {(0.9659cm, -0.05882cm)},
    z  = {(0cm, 1cm)},
    every node/.style ={draw,
                       circle, minimum size = 1.8pt,
                       inner sep = 0pt, outer sep = 0pt}] 

    \begin{scope}[canvas is yx plane at z = 0,
                  every node/.append style ={ color = black!60}]
        \node (1) at  (2, 3)   {};
        \node (2) at  (3, 3)   {};
        \node (3) at  (3, 2)   {};
        \draw (1.center) -- (2.center) -- (3.center) -- cycle;
    \end{scope}

    \begin{scope}[every node/.append style ={ color = blue} ]
        \node[yshift=1.5 cm]  at  (1)   {};
        \node[yshift=1.5 cm]  at  (2)   {};
        \node[yshift=1.5 cm]  at  (3)   {};   
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
\node [color = blue!60] at (1) {}; is still positioned at z=0 in the scope where the yx plan is at z=1.5 (that's my real problem: I don't use circle in my real code, I just provided a minimalist example with nodes' shapes I dont'really care about) –  user8947 Dec 26 '11 at 8:06
    
@user8947 Yes but it's normal that the blue node is still positioned at z=0 because you used at (1) and (1) is defined with z=0!! The coordinates of a defined node are not changed inside or outside a scope ! –  Alain Matthes Dec 26 '11 at 8:08
    
Sure, but the user only specifies the (x,y) coordinates of node (1) :D In other words, how to just use the user-specified (x,y)coordinates of (1) and the correct z (defined in the scope) Is there a way without \pgfextractx and such ? –  user8947 Dec 26 '11 at 8:09
    
I don't understand... sorry ! Inside the scope If you want to use (x,y) you write at (2,3) and z is automatically 1.5 like the red node. You can give a name at the red node, (3) for example inside the node. (3) is different of (1). –  Alain Matthes Dec 26 '11 at 8:18
    
Sure I could do that, but I don't know the position at compile time (once again, very simple example), so I can't use (2,3) (I can only use relative placement), and the red node is just an example of where I want the blue circle to be. Here is another failed attempt from my part : \pgfextractx\mydimX{\pgfpointanchor{1}{center}} \pgfextracty\mydimY{\pgfpointanchor{1}{center}} \draw (\mydimX, \mydimY) node[color=blue!60] {}; I still get the node at z=0 even in the right scope .. –  user8947 Dec 26 '11 at 8:22
show 2 more comments

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.