Is there a TikZ equivalent to the PSTricks \ncdiag command?

The pst-node package provides the \ncdiag command, which allows you to connect two nodes with a diagonal line, but with an extra arm parameter which puts a bend in the line and allows the connections at each end to meet the node perpendicularly. Is there a simple way to get this effect in TikZ?

Here's an example (compile with latex or xelatex).

\documentclass{article}
\usepackage{tikz}
\usepackage{pst-node}
\begin{document}

\rput(0,3){\rnode{A}{Foo}}
\rput(2,0){\rnode{B}{Bar}}
\ncdiag[angleA=-90,angleB=90,arm=5mm]{A}{B}
\hspace{2in}
\begin{tikzpicture}
\node at (0,0) (A) {Bar};
\node at (-2,3) (B) {Foo};
\draw[thick] (A) -- (B);
\end{tikzpicture}
\end{document}


-
You can specify the arm lengths individually as armA=<len> or armB=<len>, or both using arm=<len> (similar to specifying the angle for each individual node). –  Werner Aug 11 '11 at 15:35
@Werner Yes, thanks. I know how the pstricks command works; I'm really looking for how to do it in tikz, since I've mainly moved away from using pstricks, (although I used to use it a lot.) –  Alan Munn Aug 11 '11 at 15:44
why do you use the environment pspicture? It makes no sense, especially in your case without using coordinates –  Herbert Aug 11 '11 at 15:52
@Herbert It was there from a previous version of the document. I've removed it. Thanks. –  Alan Munn Aug 11 '11 at 16:04
@Herbert: Why does \rnode{}{\rput(){}} not work while \rput(){\rnode{}{}} works? –  xport Aug 11 '11 at 22:35

Here's my first shot. I do it using a to path, which allows me to replace a path by something else. The first bit of the arm is easy enough, but the second needs the calc library. Also, when applied to nodes then the arm length is relative to the centre of the node, not the length of path that is actually drawn.

Code:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/25474/86}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pst-node}

\tikzset{
arm angleA/.initial={0},
arm angleB/.initial={0},
arm length/.initial={0mm},
arm/.style={
to path={%
(\tikztostart) -- ++(\pgfkeysvalueof{/tikz/arm
angleA}:\pgfkeysvalueof{/tikz/arm length}) -- ($(\tikztotarget)+ (\pgfkeysvalueof{/tikz/arm angleB}:\pgfkeysvalueof{/tikz/arm length})$)
-- (\tikztotarget)
}
},
}

\begin{document}

\rput(0,3){\rnode{A}{Foo}}
\rput(2,0){\rnode{B}{Bar}}
\ncdiag[angleA=-90,angleB=90,arm=5mm]{A}{B}
\hspace{2in}
\begin{tikzpicture}
\node at (0,3) (A) {Foo};
\node at (2,0) (B) {Bar};
\draw[thick] (A) to[arm, arm angleA=-90,arm angleB=90,arm length=5mm] (B);
\end{tikzpicture}
\end{document}


(Note: I changed the node positions in the TikZ one to match the PSTricks specification.)

Picture, PSTricks on left, TikZ on right:

-
what you have is not the arm length, it is the distance from the node center, better seen with angleA=0. And by the way, to compare both delete the [br] and [tl] they make no sense, use [lb] –  Herbert Aug 11 '11 at 16:39
I guess to exactly match pstricks, you'd have to start from A.angleA, set inner sep=0 and write a wrapper with \tikzmark and [remember picture,overlay]. However, I don't think the point of this question is to copy pstricks. –  Caramdir Aug 11 '11 at 17:14
@Caramdir: Also, that would only work for nodes. This works for any coordinates. –  Loop Space Aug 11 '11 at 19:03

It needs further adjustments but I think this is also a valid yet quick and dirty solution. It can be embedded in a short function.

Also a minor detail about the positioning of the node : you might want to anchor the matrices because the absolute positioning of the text is not exactly aligned to the coordinates where I declare.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}

\matrix[matrix of nodes,row sep = 2mm] (B) at (2,0)
{
\node[inner sep=1mm] {}; \\
\node {Bar}; \\
};

\matrix[matrix of nodes,row sep = 2mm] (F) at (0,3)
{
\node {Foo}; \\
\node[inner sep=1mm] {}; \\
};

\draw (B-2-1) -- (B-1-1.north) -- (F-2-1.south) -- (F-1-1.south);
\end{tikzpicture}
\end{document}


You can play with the row sep to extend or shorten the arms.

Cheers,

-