3

I'd like to know if there is an automatic way of producing edges orthogonal to the nodes. In particular this would be useful when the nodes are automatically rotated. An example:

enter image description here

I'd like to connect the node "long text" with "C" but having the edge (in red) orthogonal to the node like in B.

\documentclass[border=5pt,convert={density=300,size=1080x800,outext=.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}

\begin{document}

\begin{tikzpicture}

\node[rectangle,draw] (A) at (6,0) {A};
\node[rectangle,draw,rotate=+35] (B) at (2,-3) {B};

\node [rectangle,draw] (C) at (5,0) {C};

\path (A) edge [in=90+35,out=-90] node (long) [draw,midway,sloped,rotate=-90,fill=white] {long text} (B) ;

% I'd like to connect (long) with C having the edge orthogonal to both the  nodes

 \draw   ($(long.north west)!.3!(long.north east)$)  edge [in=-90,red] ($(C.south west)!.3!(C.south east)$);

\end{tikzpicture}

\end{document}

I tried with the option "relative" but, in this case, the in/out angles are relative to the edge, not to the node.

I posed this question also in Define a new rectangular node with several anchor points in tikz , but I think it can deserve a questions by itself.

Side question: I don't understand why the edge starting from (B) does not start from the center of the (B) but it is slightly on its left.

4

Depending on how often you need to access this information, you can make a math function and so on but the essential idea is to get the orientation using either anchors or anything that has the slope. For example you can use the frontend with let syntax.

\usetikzlibrary{calc}% In the preamble


\begin{tikzpicture}
\node[draw] (A) at (6,0) {A};
\node[draw,rotate=35] (B) at (2,-3) {B};
\node [draw] (C) at (5,0) {C};
\path (A) edge [in=90+35,out=-90] 
      node (long) [draw,midway,sloped,rotate=-90,fill=white] {long text} (B) ;

\draw let 
      \p1=($(long.north)-(long.north east)$),
      \n1={atan2(\y1,\x1)} 
      in  
($(long.north west)!.3!(long.north east)$) edge [in=-90,out=\n1-90,red] 
($(C.south west)!.3!(C.south east)$);
\end{tikzpicture}

enter image description here

  • thank you!! Since I'm going to repeat it several times, do you have any suggestion on how to make it automatical using a mathematical function? I thought something like \newcommand{\EdgeOrthTo}[2] { \draw let \p1=($(#1.north)-(#1.north east)$), \n1={atan2(\y1,\x1)}, \p2=($(#2.north)-(#2.north east)$), \n2={atan2(\y2,\x2)} in ($(#1.north west)!.3!(#1.north east)$) edge [in=\n2+90,out=\n1-90,red] ($(#2.south west)!.3!(#2.south east)$); } But I'd like to make it more tikz friendly, namely using a new style (like e.g. edge [ !-!] ). Any hint? – Podantoro Jun 1 '15 at 14:54
  • Sorry, it was unreadable! Here a copy of the code I wrote above gist.github.com/anonymous/721fe205aa2a18f7a20b one can just write \EdgeOrthTo{long}{C} – Podantoro Jun 1 '15 at 16:25
  • I asked regarding this "automatization process" in another question: tex.stackexchange.com/q/248063/58947 – Podantoro Jun 1 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.