将节点放置在两条水平线之间的任意位置后,我想绘制到点 B 的对角线,然后绘制一系列斜线,如下图所示:
它们都应该具有相同的斜率。
点A
是两条线之间的一个一般点; 点B
是属于上一条线的一个一般点。它始终位于 的右侧A
。
我尝试使用此代码。
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\coordinate (a0) at (0,0);
\coordinate (a1) at (10,0);
\coordinate (a2) at (10,4);
\coordinate (Bbase) at (6,-1);
\draw (a0) -- (a1);
\draw (a0 |- a2) -- (a2);
\node (A) at (2,1) {A};
\draw (A) -- (Bbase |- a2) node[above] {B};
\end{tikzpicture}
\end{document}
结果如下:
如何进行?解决方案不应取决于此特定情况的斜率:无论是什么,都应确定正确的斜率A
(B
只要它们符合上面列出的条件)。
答案1
钛钾Z 有一个称为 zigzag 的装饰。很可能我误解了这个问题。这是一个绘制延续的宏。(\gettikzxy
目前不需要,但如果您打算使此宏更灵活,它可能会很有用。)
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{decorations.pathmorphing,intersections}
\makeatletter % from https://tex.stackexchange.com/a/412901/121799
\newcommand{\Distance}[3]{% % from https://tex.stackexchange.com/q/56353/121799
\tikz@scan@one@point\pgfutil@firstofone($#1-#2$)\relax
\pgfmathsetmacro{#3}{veclen(\the\pgf@x,\the\pgf@y)/28.45274}
}
% from https://tex.stackexchange.com/q/56353/121799
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\global\edef#2{\the\pgf@x}%
\global\edef#3{\the\pgf@y}%
}
\makeatother
\newcommand{\DrawZigZags}[5][]{% #2=A, #3=B, #4=lower line, #5=end
\Distance{(#2)}{(#2-|#3)}{\myx}
\Distance{(#2)}{(#2|-#3)}{\myy}
\Distance{(#2)}{(#2|-#4)}{\myz}
\typeout{\myx,\myy,\myz}
\path[name path=AB] (#2) -- (#3);
\path[name path=hori] (#2|-0,{0.5*(\myy+\myz)*1cm}) --
(#5|-0,{0.5*(\myy+\myz)*1cm});
\path[name intersections={of=AB and hori, name=start}];
\draw [decorate, decoration={zigzag,amplitude={0.5*(\myy+\myz)*1cm},segment
length={2*(\myx/\myy)*(\myy+\myz)*1cm}},#1]
(start-1) -- (start-1-|#5);
}
\begin{document}
\begin{tikzpicture}
\coordinate (a0) at (0,0);
\coordinate (a1) at (18,0);
\coordinate (a2) at (18,4);
\coordinate (Bbase) at (4,-1);
\draw (a0) -- (a1);
\draw (a0 |- a2) -- (a2);
\node (A) at (2,1) {A};
\draw (A) -- (Bbase |- a2) node[above] {B};
\coordinate (B) at (Bbase |- a2);
\DrawZigZags[blue]{A}{B}{a0}{19.1,0}
\end{tikzpicture}
\end{document}