2

In this code, related to a previous question,

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{arrows.meta,calc}

\begin{document}

\begin{tikzpicture}

\draw[->] (-3,0,0) -- (3,0,0) node[below right] {$x$};
\draw[->] (0,-3,0) -- (0,3,0) node[above right] {$y$};
\draw[->] (0,0,-3) -- (0,0,3) node[below right] {$z$};

\coordinate (o) at (0,0,0);
\coordinate (a) at (3.1,0,1.2);

\draw[dashed] (a) -- (o);

\path (a) -- coordinate[pos=0.32] (b) (o);

\draw [thick,-{Straight Barb},orange] (a) -- ($(a)!1.2cm!90:(o)$) node[black,above left] (c) {c};
\draw[thick,-{Straight Barb},gray] (a) -- node[pos=0.7, below=0.35em] {b} (b);
\draw [thick,-{Straight Barb},red] (a) -- ([shift={(0,1.5,0)}]a) node[black,below right] (d) {d};

\draw[thick] ($(a)!1.2cm!90:(o)$) -- (a);
\draw[thick] (c) -- (a);

\draw ([shift={(0,0,-2.1)}]a) -- ([shift={(0,0,2.1)}]a);

\coordinate (newd) at (d);

\draw ([shift={(0,0,-2.1)}]newd) -- ([shift={(0,0,2.1)}]newd);

\end{tikzpicture}

\end{document}

Two unexpected outputs are generated:

enter image description here

1) The point c doesn't coincide with the point ($(a)!1.2cm!90:(o)$), so two different segments are drawn: why? What does actually realize the expression ($(a)!1.2cm!90:(o)$)? I would like to obtain a point in the (x,z) plane which is orthogonal to the line between a and o.

2) The line

\draw ([shift={(0,0,-2.1)}]newd) -- ([shift={(0,0,2.1)}]newd);

does not reach the tip of the red arrow. Why?

In both cases it seems that the node position does not coincide with its definition.

BowPark
  • 1,213
  • 1
    Nodes (unlike coordinates) have a finite size. So you may want to use coordinate and label. –  Apr 23 '18 at 15:41

1 Answers1

2

Just spelling out my comment: use coordinates instead of nodes, as the latter have finite sizes.

enter image description here

\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}

\draw[->] (-3,0,0) -- (3,0,0) node[below right] {$x$};
\draw[->] (0,-3,0) -- (0,3,0) node[above right] {$y$};
\draw[->] (0,0,-3) -- (0,0,3) node[below right] {$z$};

\coordinate (o) at (0,0,0);
\coordinate (a) at (3.1,0,1.2);

\draw[dashed] (a) -- (o);

\path (a) -- coordinate[pos=0.32] (b) (o);

\draw [thick,-{Straight Barb},orange] (a) -- ($(a)!1.2cm!90:(o)$)
coordinate[label={[black]above left:c}] (c);
\draw[thick,-{Straight Barb},gray] (a) -- node[pos=0.7, below=0.35em] {b} (b);
\draw [thick,-{Straight Barb},red] (a) -- ([shift={(0,1.5,0)}]a) 
coordinate[black,label={[black]below right:d}] (d);

\draw[thick] ($(a)!1.2cm!90:(o)$) -- (a);
\draw[thick] (c) -- (a);

\draw ([shift={(0,0,-2.1)}]a) -- ([shift={(0,0,2.1)}]a);

\coordinate (newd) at (d);

\draw ([shift={(0,0,-2.1)}]newd) -- ([shift={(0,0,2.1)}]newd);

\end{tikzpicture}

\end{document}