我想画一条线,就像
\coordinate (A) at (0.42,0.5);
\coordinate (B) at (0.98,0.44);
\draw[ultra thick] (A) -- (B);
并在这条线上画出一系列小线段,其中
- 第一个以(B)为中心,
- 第二个在(A)方向上稍远一点,并且稍微旋转了一下,
- 这次的口渴比第二次的要远一些,而且旋转得更多一些,……
依此类推,直到点 (A)。
我最终得到了下面的代码,但它根本不起作用。
\foreach \i in {0,0.1,..,1}{%
\node [draw, rotate=180*\i] at (A)!\i!(B) {%
\begin{tikzpicture}
\draw (-0.1,0) -- (0.1,0);
\end{tikzpicture}};
}
补充说明:(B)和(A)处的小线段的角度应该可控。例如,我想绘制一个旋转 180º 的线段序列或一个旋转 720º 的线段序列
答案1
我不太明白你的意思,但你可以把这作为一个起点
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (3,0);
\coordinate (b) at (0,1);
\draw (a) -- (b);
\foreach \i in {0,1,...,10} {
\coordinate (x) at ($(a)!{\i/10}!(b)$);
\draw ($(x)+({90-(4.5*\i)}:0.5)$) -- ($(x)+({-90-(4.5*\i)}:0.5)$);
}
\end{tikzpicture}
\end{document}
您可以根据此代码构建一个宏
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (3,0);
\coordinate (b) at (0,1);
\draw (a) -- (b);
\def\beginangle{85}
\def\endangle{143}
\def\leng{1}
\foreach \i in {0,...,10} {
\coordinate (x) at ($(a)!{\i/10}!(b)$);
\draw ($(x)+({\beginangle-((\beginangle-\endangle)*\i/10)}:{\leng/2})$) -- (x) coordinate[pos=2] (y) (x) -- (y);
}
\end{tikzpicture}
\end{document}
答案2
只是为了好玩:使用 的版本decorations.markings
。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[rotated bar step/.initial=0.0499,
rotated bar length/.initial=2mm,
rotated bar start angle/.initial=90,
rotated bars/.style={%
postaction={decorate,decoration={markings,
mark=between positions 0 and 1 step \pgfkeysvalueof{/tikz/rotated bar step} with
{\pgfmathsetmacro{\barangle}{(\pgfkeysvalueof{/pgf/decoration/mark info/sequence
number}-1)*\pgfkeysvalueof{/tikz/rotated bar step}*#1+\pgfkeysvalueof{/tikz/rotated bar start angle}}
\draw (\barangle:\pgfkeysvalueof{/tikz/rotated bar length}/2)
-- (\barangle+180:\pgfkeysvalueof{/tikz/rotated bar length}/2);}}}}]
\draw[rotated bars=720] (0,1) -- (3,0);
\draw[rotated bar length=4mm,rotated bar step=0.0999,rotated bars=720] (4,1) to[bend left] (7,0);
\end{tikzpicture}
\end{document}