[Tex/LaTex] How to use \pgfextractx, \setlength and so on together, to achieve a task using paths

tikz-pgf

The following code attempts to absolutely position two nodes with rectangular outlines, then draw a line that goes from the right-hand side of one to the left-hand side of the other, along orthogonal lines with the vertical segment lying directly between the two nodes. But instead of getting that result, this happens:

alt text

I can't get the hang of how LaTeX and TikZ length commands work. How can I fix what I've got here?

\documentclass[a4paper]{amsart}

\usepackage{calc,fullpage,tikz}
\usetikzlibrary{arrows}

\newlength{\mylengthA}
\newlength{\mylengthB}
\newlength{\mylengthC}

\begin{document}

\begin{center}\begin{tikzpicture}
[yscale = -1]

\begin{scope} % Boxes
[ every node/.style = { draw,
                        rectangle,
                        inner sep = 3mm,
                        }
  ]
    \node (a) at (0,20mm) {Apple};
    \node (b) at (28mm,0) {Banana};
\end{scope}

\begin{scope} % Arrows
[->, > = angle 90, very thick]
    \pgfextractx{\mylengthA}{(a.east)}
    \pgfextractx{\mylengthB}{(b.west)}
    \setlength{\mylengthC}{\mylengthA/2 + \mylengthB/2}
    \draw (\mylengthA,20mm) -- (\mylengthC,20mm) |- (\mylengthB,0);
\end{scope}

\end{tikzpicture}\end{center}

\end{document}

Best Answer

This works:

% mark the midpoint between nodes a and b
\path (a.east) -- (b.west) node[coordinate,midway] (c) {};
% Arrows
\draw[->,>=angle 90, very thick] (a.east) -| (c) |- (b.west);

You almost never have to use \pgfextracts. Instead, use named coordinate nodes and transformations.