3

Please, consider the following (not so minimal) MWE. Why the distance between points named a3 and b3 is not the same as the vertical distance between points a2 and b2 (it is about 30% larger)? From my code follows, that b3 is for vertical distance between a2 andb2 right from a3.

enter image description here

\documentclass[border=5mm,
               tikz,%class=zfc-book2b,
               preview]{standalone}
\usetikzlibrary{calc,intersections,positioning}
%---------------------------------------------------------------%
        \begin{document}
\begin{tikzpicture}[
X/.style = {inner sep=0pt},
   every   pin/.style  = {inner sep=1pt, align=center,
                          font=\footnotesize\sffamily,
                          pin edge={<-,solid,black,shorten <=1pt}
                          }
                    ]
    \begin{scope}[yshift=20mm]
\draw[red,thick]
    (-2.2,-1) -- (-1.5,-1.0) coordinate[pin=120:a1] (a1)
              |- (-0.5,-0.5) coordinate[pin=120:b1] (b1)
              |- ( 0.5, 0.0) 
              |- (1.5,0.5) |- (2.2,1);
%--- axis
\draw[->]   (-2.2,0) -- (2.4,0) node[below left] {$V_i$};
\draw[->]   (0,-1.2) -- (0,1.7) node[below left] {$q(t),\ V_o$};
    \end{scope}
\draw[red,thick,name path=A]
    plot[domain=0:120, samples=59]  ({2*sin(\x+120)},-2+\x/60);
\draw[->]   (-2.2,0) -- (2.4,0) node[above left] {$x(t)$};
\draw[->]   (0, 0.1) -- (0,-2)  node[above left] {$t$};
    \begin{scope}[yshift=20mm,xshift=40mm]
\draw[->]   (-1.2,0) -- (4.4,0) node[below left] {$t$};
\draw[->]   (0,-1.2) -- (0,1.7) node[below left] {$x_q(t)$};
    \end{scope}
\coordinate             (a3)    at (4.5,2);
    \path[name path=B]  (a1) -- + (0,-2.5);
    \path[name path=C]  (b1) -- + (0,-3.0);
\coordinate[name intersections={of=A and B, by=a2}];
\coordinate[name intersections={of=A and C, by=b2}];
\path   let \p1 = (a2),
            \p2 = (b2),
            \n1 = {veclen(\y1,\y2)} in
        coordinate[right=\n1 of a3] (b3);
\draw[->,dashed]    
    (a1) -- (a2) node[X,pin=240:a2] {} -| (a3) node[X,pin=90:a3] {};
\draw[->,dashed]    
    (b1) -- (b2) node[X,pin=240:b2] {} -| (b3) node[X,pin=90:b3] {};
    \end{tikzpicture}
        \end{document}

I gave my best to write above code in accordance with instructions in TikZ manual as well as in similar question on SE, however the result is not as expected. I give up in searching what is wrong in above MWE ...

Zarko
  • 296,517

1 Answers1

4

Maybe it helps to replace

\path   let \p1 = (a2),
            \p2 = (b2),
            \n1 = {veclen(\y1,\y2)} in
        coordinate[right=\n1 of a3] (b3);

by

\path   let \p1 = (a2),
            \p2 = (b2),
            \n1 = {\y1 - \y2} in
        coordinate[right=\n1 of a3] (b3);

? veclen() is useful for 2D vectors, but you just want the difference between two y coordinates.

result

With screen ruler:

result with screen ruler

wrtlprnft
  • 3,859
  • I nowhere see this possibility for calculation of lengths ... and it works! Thank you for help – Zarko Apr 13 '16 at 10:24
  • 1
    +1 and works, although it's quite surprising... I expected the same result. – Rmano Apr 13 '16 at 10:27
  • @Rmano thanks for the ruler! Just another suggestion, matching the topic of confusing coordinate calculations: \draw[blue] let \p a = (a2 -| a3), \p b = (b2 -| b3) in (\p a) circle[radius=\x b - \x a]; – wrtlprnft Apr 13 '16 at 11:05