请考虑以下(不是那么最小的)MWE。为什么名为a3
和的点之间的距离与点和b3
之间的垂直距离不同(大约大 30%)?从我的代码可以看出,这是从和之间的垂直距离。a2
b2
b3
a2
b2
a3
\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}
我尽力按照 TikZ 手册以及 SE 上类似问题的说明编写了上述代码,但结果并不如预期。我放弃寻找上述 MWE 中的问题所在...
答案1
也许它有助于取代
\path let \p1 = (a2),
\p2 = (b2),
\n1 = {veclen(\y1,\y2)} in
coordinate[right=\n1 of a3] (b3);
经过
\path let \p1 = (a2),
\p2 = (b2),
\n1 = {\y1 - \y2} in
coordinate[right=\n1 of a3] (b3);
?veclen()
对于二维向量很有用,但您只想知道两个 y 坐标之间的差异。
和屏幕标尺: