此代码:
\documentclass[tikz,border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \x in {1,...,10}{
\draw (-1+0.1*\x,1+0.1*\x) -- (1+0.1*\x,-.5+0.1*\x);
}
\draw[->,thick, xshift=5mm,yshift=2mm] (0,0) -- (0,0.2) node (r1) [right] {};
\draw[->,thick, xshift=15mm,yshift=5mm] (0,0) -- (0,0.2) node (r1) [right] {};
\end{tikzpicture}
\end{document}
产生以下输出:
我该怎么做才能使箭头与线条正交并且它们的原点恰好从一条线条开始?
答案1
对于每一行“i”,我添加了两个点“Ai”和“Bi”(如果需要,可以添加更多),它们可以用作矢量的起点
\documentclass[tikz,border=1mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \x in {1,...,10}{
\draw (-1+0.1*\x,1+0.1*\x) -- (1+0.1*\x,-.5+0.1*\x)
coordinate[pos=.8](A\x) coordinate[pos=.7](B\x);
}
\draw[->,thick] (B2) -- +(0.1,0.1) node (r1) [right] {};
\draw[->,thick] (A8) -- +(0.1,0.1) node (r1) [right] {};
\end{tikzpicture}
\end{document}
答案2
如果我们能够改进萨利姆·布的回答再多一点。
\documentclass[margin=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \x in {1,...,10}{
\pgfmathtruncatemacro{\y}{\x*100};
\draw (-1+0.1*\x,1+0.1*\x)coordinate(\x) -- (1+0.1*\x,-.5+0.1*\x)coordinate(\y) ;}
\coordinate (E0) at ($ (1)!.75!(100) $);
\draw[-latex,red] (E0) --++ (45:0.15);
\coordinate (E1) at ($ (3)!.25!(300) $);
\draw[-latex,orange] (E1) --++ (45:0.35);
\coordinate (E2) at ($ (5)!.8!(500) $);
\draw[-latex,blue] (E2) --++ (45:0.45);
\end{tikzpicture}
\end{document}