I adapted the code of Paul Gaborits answer to make it more general.
I used abs
and sign
to allow other use cases.
More generalized version:
With the option to[diagonal line]
for a connection, first a diagonal (45°) and then a horizontal or vertical line is drawn. If the angle between start and end point is a multiple of 45°, only a single direct line is drawn.
Code:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{
diagonal line/.style={
to path={
let \p{start}=(\tikztostart),
\p{target}=(\tikztotarget),
\p{diff}=({\x{target}-\x{start}}, {\y{target}-\y{start}}),
\p{absdiff}=({abs(\x{diff})}, {abs(\y{diff})}),
\n{mindiff}={min(\x{absdiff}, \y{absdiff})},
\p{inter}=(
{sign(\x{diff}) * \n{mindiff}},
{sign(\y{diff}) * \n{mindiff}}
)
in
\ifnum \ifdim\x{target}=\x{start} 1
\else \ifdim\y{target}=\y{start} 1
\else \ifdim\x{absdiff}=\y{absdiff} 1
\else 0\fi\fi\fi=1 %primitive tex or condition
-- (\tikztotarget)
\else
--++ (\p{inter}) -- (\tikztotarget)
\fi
},
},
}
\begin{document}
\begin{tikzpicture}
\foreach \d in {1,...,16} {
\node (a\d) at ($(0,0)+(90-\d*22.5:12mm)$) {\footnotesize $a_{\d}$};
\node (b\d) at ($(0,0)+(90-\d*22.5:35mm)$) {\footnotesize $b_{\d}$};
\draw (a\d) to[diagonal line] (b\d);
}
\end{tikzpicture}
\end{document}
Result:
Older non-general version
Code:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\tikzset{
special line/.style={
to path={
let \p{start}=(\tikztostart), \p{target}=(\tikztotarget),
\p{inter}=({\x{start} + sign(\x{target}-\x{start}) * abs(\y{target}-\y{start})}, \y{target})
in -- (\p{inter}) -- (\tikztotarget)
},
},
}
\begin{document}
\begin{tikzpicture}
\node (x) at (0,0) {(0,0)};
\node (y1) at (5,2) {(5,2)};
\node (y2) at (5,-2) {(5,-2)};
\node (y3) at (-5,-2) {(-5,-2)};
\node (y4) at (-5,2) {(-5,2)};
\draw (x) to[special line] (y1);
\draw (x) to[special line] (y2);
\draw (x) to[special line] (y3);
\draw (x) to[special line] (y4);
\end{tikzpicture}
\end{document}
Result:
The result with Pauls or Ignasis code would be:
/-
operator to parallel|-
.