TikZ: Understanding the usage of calc library
Your approach does not work because you try to use {
and }
where you should use ($
and $)
. You can definitely do that without auxiliary coordinates and actually even without calc
.
\documentclass{article}
\usepackage{tikz,mathtools,amssymb}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
tmp/.style = {coordinate},
sum/.style= {draw, fill=white, circle, node distance=1cm},
input/.style = {coordinate},
output/.style= {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}
}
}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
\node [sum] (sum2) {};
\node [block, right = 1cm of sum2](ractuator){$\frac{2}{s+2}$};
\node [block, right = 1cm of ractuator,] (vdynamics) {$\frac{-0.125(s+0.437)}{(s+1.29)(s+0.193)}$};
\node [block, right = 1cm of vdynamics,] (integrator) {$\frac{1}{s}$};
\node [output, right = 1.5cm of integrator] (output) {};
\node [block] (yaw) at
($(0,-2cm)+($(output)!0.5!(integrator)$)!0.5!(sum2)$) {C};
%
\draw [->] (ractuator) -- (vdynamics);
\draw [->] (vdynamics) -- (integrator);
\draw [->] (integrator) -- node[name=heading]{$\Psi(s)$} (output)
coordinate[midway] (aux);
\draw (aux) |- (yaw) -| (sum2);
\end{tikzpicture}
\bigskip
\begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
\node [sum] (sum2) {};
\node [block, right = 1cm of sum2](ractuator){$\frac{2}{s+2}$};
\node [block, right = 1cm of ractuator,] (vdynamics) {$\frac{-0.125(s+0.437)}{(s+1.29)(s+0.193)}$};
\node [block, right = 1cm of vdynamics,] (integrator) {$\frac{1}{s}$};
\node [output, right = 1.5cm of integrator] (output) {};
\node [block] (yaw) at
([yshift=-2cm]barycentric cs:output=1,integrator=1,sum2=2) {C};
%
\draw [->] (ractuator) -- (vdynamics);
\draw [->] (vdynamics) -- (integrator);
\draw [->] (integrator) -- node[name=heading]{$\Psi(s)$} (output)
coordinate[midway] (aux);
\draw (aux) |- (yaw) -| (sum2);
\end{tikzpicture}
\end{document}
I don't know how complex expression can be understood by calc
but instead of trying to understand how to write such expression, I think it's easier to use an auxiliar coordinate and solve the problem:
\documentclass{article}
\usepackage{tikz,mathtools,amssymb}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
tmp/.style = {coordinate},
sum/.style= {draw, fill=white, circle, node distance=1cm},
input/.style = {coordinate},
output/.style= {coordinate},
pinstyle/.style = {pin edge={to-,thin,black}
}
}
\begin{tikzpicture}[auto, node distance=2cm,>=latex',align=center]
\node [sum] (sum2) {};
\node [block, right = 1cm of sum2](ractuator){$\frac{2}{s+2}$};
\node [block, right = 1cm of ractuator,] (vdynamics) {$\frac{-0.125(s+0.437)}{(s+1.29)(s+0.193)}$};
\node [block, right = 1cm of vdynamics,] (integrator) {$\frac{1}{s}$};
\node [output, right = 1.5cm of integrator] (output) {};
\coordinate (aux) at ($(integrator.east)!.5!(output)$);
\node [block] (yaw) at ([yshift=-2cm]$(aux)!0.5!(sum2)$) {C};
\draw (aux) |- (yaw);
\draw (yaw)-|(sum2);
%
\draw [->] (ractuator) -- (vdynamics);
\draw [->] (vdynamics) -- (integrator);
\draw [->] (integrator) -- node[name=heading]{$\Psi(s)$} (output);
\end{tikzpicture}
\end{document}
Here, to simplify the code, I'll replace (integrator)
with (A)
, (output)
with (B)
and (sum2)
with (C)
.
There is two things not right with
($ (A) + 0.5*{ (B)-(A) }!0.5!(C) $)
.
First, I don't think you can use
{}
, with the calc package, for the coordinate part. For me, it only works for with scalar. So($ {2+2}*(A) $)
will compute, but not($ 2*{(A)+(B)} $)
(or am I wrong?)The second thing is that this formula doesn't seem to correspond to the point you want. I kind of get that you want to start from (A), "move" to the middle of [AB] and continue like that, but you mix relative (B-A) and absolute positioning (C). One right formula would have been
($ { (A) + 0.5*{(B)-(A)} }!0.5!(C) $)
. But because tikz can't do the computation, you'll have to give the expanded formula:($ .25*(A) + .25*(B) + .5*(C)$)
.
One other way to do it is ($ (A) !.5! (B) !.5! (C) $)
. Here, we take the middle of (A) and (B), and then the middle of the result and (C).
I hope this will answer your interrogations!
You can test the three solutions here (the last one with temporary coordinate):
\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[line width=1]
\draw[black!10] (0,0) grid (4,4);
\node (A) at (1,1) {A};
\node (B) at (3,1) {B};
\node (C) at (2,3) {C};
%% 1
\draw[red] ($ (A) !.5! (B) !.5! (C) $) circle (.05);
%% 2
\draw[orange] ($ .25*(A) + .25*(B) + .5*(C) $) circle (.1);
%% 3
\coordinate (foo) at ($ (A) !.5! (B) $);
\draw[yellow] ($ (foo) !.5! (C) $) circle (.15);
\end{tikzpicture}
\end{document}
which gives