3

I'm currently drawing the following diagram:

enter image description here

For some reason one of the arrows do not touch the block IFOC. How do I fix that?

My code:

\documentclass[tikz,border=2pt]{standalone}

% Inclui subpacotes
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{babel}
\usetikzlibrary{calc,arrows.meta,patterns,backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}

% Define subcomandos
\tikzstyle{line} = [draw, -latex']
\tikzstyle{block} = [draw, rectangle, rounded corners, minimum size=1cm, text centered]
\tikzstyle{circulo} = [draw, circle, minimum size=0.7cm, text centered]
\tikzstyle{triangulo} = [draw, thick, isosceles triangle, minimum height=1cm, isosceles triangle apex angle=60]
\tikzstyle{joint} = [draw, circle, fill, inner sep=0pt, minimum size=3pt]

\begin{document}

\tikzset{pics/transform/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/transform/width}/2,\pgfkeysvalueof{/tikz/transform/height}/2)
 node[below right] (tl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/transform/width}/2,-\pgfkeysvalueof{/tikz/transform/height}/2)
 node[above left] (br) {#1};
 \node[pic actions,inner sep=0pt,fit=(tl)(br),path picture={\path[pic actions]
 (path picture bounding box.north east)
 -- (path picture bounding box.south west);}] 
 (\pgfkeysvalueof{/tikz/transform/name}){};
}},transform/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=}

\tikzset{pics/inverter/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/inverter/width}/2,-\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[above right,scale=2] (bl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/inverter/width}/2,\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[below left,scale=2] (tr) {#1};
 \node[pic actions,inner sep=0pt,fit=(bl)(tr),path picture={\path[pic actions]
 (path picture bounding box.north west)
 -- (path picture bounding box.south east);}] 
 (\pgfkeysvalueof{/tikz/inverter/name}){};
 \node at (0,\pgfkeysvalueof{/tikz/inverter/height}/2) 
 [rectangle, above]{\pgfkeysvalueof{/tikz/inverter/title}};
}},inverter/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=,%
title/.initial=PWM Inverter}

\begin{tikzpicture}[auto, node distance=2cm, >=latex']
\path pic[draw,rounded corners,text centered,transform/name=trans1] {transform={$abc$}{$qd0$}}
(0,-3) pic[draw,rounded corners,text centered,transform/name=trans2] {transform={$abc$}{$qd0$}}
(-3,0) node[block,minimum size=2cm](ifoc){IFOC};
\node at (0,-1.5) [joint](j4){};

% arrows
\draw[->] (-2,0.35)-- node{$v_{qs}^{\lambda}$} (-1,0.35);
\draw[->] (-2,-0.35)-- node{$v_{ds}^{\lambda}$} (-1,-0.35);
\draw[->] (-1,-2.65)-|node[above,pos = 0.15873]{$i_{qs}^{\lambda}$}(-2.5,-1);
\draw[->] (-1,-3.35)-|node[above,pos = 0.11494]{$i_{ds}^{\lambda}$}(-3.0,-1);
\draw[->] (ifoc)--(-1.5,-1.5)-|node[above,pos = 0.35]{$\theta^{\lambda}$}(trans1);
\draw[->] (j4)--(trans2);
\end{tikzpicture}
\end{document}
  • 3
    It is due to the rounded corners. One solution might be to shift the coordinates, such as, \draw[->] ([shift={(-0.5mm,0.5mm)}]ifoc.-45)--(-1.5,-1.5)-|node[above,pos = 0.35]{$\theta^{\lambda}$}(trans1); – ferahfeza Aug 16 at 22:33
  • 1
    Possible duplicate, and the solution to your issue is this: \draw[->,shorten <= -2.5pt+\pgflinewidth] (ifoc)--(-1.5,-1.5)-|node[above,pos = 0.35]{$\theta^{\lambda}$}(trans1); (copied from there and modified to fit your need). – M. Al Jumaily Aug 16 at 22:38
2

As mentioned in the comments, the gap is due to the rounded corners. One way to fix the problem is to compute the intersection of the node boundary path with a continuation of the line to the center. This method also works if you want to terminate the line with an arrow, otherwise you could just use clip.

\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{arrows}
\usetikzlibrary{fit}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}

% Define styles: use \tikzset !
\tikzset{block/.style={draw, rectangle, rounded corners, minimum size=1cm, text
centered},
joint/.style={draw, circle, fill, inner sep=0pt, minimum size=3pt}}

\begin{document}

\tikzset{pics/transform/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/transform/width}/2,\pgfkeysvalueof{/tikz/transform/height}/2)
 node[below right] (tl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/transform/width}/2,-\pgfkeysvalueof{/tikz/transform/height}/2)
 node[above left] (br) {#1};
 \node[pic actions,inner sep=0pt,fit=(tl)(br),path picture={\path[pic actions]
 (path picture bounding box.north east)
 -- (path picture bounding box.south west);}] 
 (\pgfkeysvalueof{/tikz/transform/name}){};
}},transform/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=}

\tikzset{pics/inverter/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/inverter/width}/2,-\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[above right,scale=2] (bl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/inverter/width}/2,\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[below left,scale=2] (tr) {#1};
 \node[pic actions,inner sep=0pt,fit=(bl)(tr),path picture={\path[pic actions]
 (path picture bounding box.north west)
 -- (path picture bounding box.south east);}] 
 (\pgfkeysvalueof{/tikz/inverter/name}){};
 \node at (0,\pgfkeysvalueof{/tikz/inverter/height}/2) 
 [rectangle, above]{\pgfkeysvalueof{/tikz/inverter/title}};
}},inverter/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=,%
title/.initial=PWM Inverter}

\begin{tikzpicture}[auto, node distance=2cm, >=latex']
\path pic[draw,rounded corners,text centered,transform/name=trans1] {transform={$abc$}{$qd0$}}
 (0,-3) pic[draw,rounded corners,text centered,transform/name=trans2]{transform={$abc$}{$qd0$}}
 (-3,0) node[block,minimum size=2cm,name path=block](ifoc){IFOC};
\node at (0,-1.5) [joint](j4){};

% arrows
\draw[->] (-2,0.35)-- node{$v_{qs}^{\lambda}$} (-1,0.35);
\draw[->] (-2,-0.35)-- node{$v_{ds}^{\lambda}$} (-1,-0.35);
\draw[->] (-1,-2.65)-|node[above,pos = 0.15873]{$i_{qs}^{\lambda}$}(-2.5,-1);
\draw[->] (-1,-3.35)-|node[above,pos = 0.11494]{$i_{ds}^{\lambda}$}(-3.0,-1);
\path[name path=line] (ifoc.center) --(-1.5,-1.5);
\draw[name intersections={of=block and line},->] (intersection-1)--(-1.5,-1.5)-|node[above,pos = 0.35]{$\theta^{\lambda}$}(trans1);
\draw[->] (j4)--(trans2);
\end{tikzpicture}
\end{document}

enter image description here

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.