我想在圆弧和一些水平线的所有交叉点处放置一个我定义的符号:
我知道如何在其他情况下使用 \foreach,但我真的不确定如何设置代码才能使其工作
例如我想放置
\def\pulse{+(0.1,0) -- +(0.2,0.1) -- +(0.3,-0.1) -- +(0.4,0)}
在圆弧线与水平线相交的每个位置,但我显然还没有达到使用 TikZ 的水平。
所以问题是,有人知道我该怎么做吗?
我认为它会是这样的
\foreach \pos in {don't know what to type here}
{
some kind of if-checking
place if true
}
但我不知道该写什么。任何帮助我都非常感谢!
谨致问候,dm
*编辑:如果有该图的代码,将会更容易提供帮助:
\tikzstyle{branch} = [circle, inner sep = 0pt, minimum size = 0.5mm, fill = black, draw = black]
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{tikzpicture}[semithick,>=latex']
\def\pulse{+(0.1,0) -- +(0.2,0.1) -- +(0.3,-0.1) -- +(0.4,0)}
\node[branch] (fp) at (-2,10) {};
\node[above] at (fp.north) {\scriptsize Focal point};
% draw rectangle in array
\draw[semithick] (2,9.5) -- (2.25,9.5) -- (2.25,5) -- (2,5) -- cycle;
% draw horizontal lines inside array
\foreach \y in {5,5.5,...,9}
\draw[semithick] (2,\y) -- (2.25,\y);
\node[above] at (2.125,9.5) {\scriptsize Array};
\foreach \y in {5.25,5.75,...,9.25}
{
% draw lines from focal point to array
\draw[semithick,->] (fp.center) -- (2,\y);
% draw VGA amplifiers
\draw[semithick,fill=white] (5.5,\y) -- ($(5.5,\y)+(0,0.2)$) -- (6,\y) -- ($(5.5,\y)+(0,-0.2)$) -- cycle;
% draw arrows thru VGA amplifiers
\begin{pgfonlayer}{background}
\draw[semithick,->] ($(5.6,\y)+(0,-0.25)$) -- ($(5.95,\y)+(0,0.2)$);
\end{pgfonlayer}
% draw ADC
\draw[semithick] (6.2,\y) -- ($(6.4,\y)+(0,0.2)$) -- ($(7.2,\y)+(0,0.2)$) -- ($(7.2,\y)+(0,-0.2)$) -- ($(6.4,\y)+(0,-0.2)$) -- cycle;
\node[] at (6.7,\y) {\scriptsize ADC};
% draw FIFO block
\draw[semithick] (7.6,\y) -- ($(7.6,\y)+(0,0.2)$) -- ($(8.4,\y)+(0,0.2)$) -- ($(8.4,\y)+(0,-0.2)$) -- ($(7.6,\y)+(0,-0.2)$) -- cycle;
\node[] at (8,\y) {\scriptsize FIFO};
% draw lines in between the blocks already drawn
\draw[semithick,->] (2.25,\y) -- (5.5,\y);
\draw[semithick,->] (6,\y) -- (6.2,\y);
\draw[semithick,->] (7.2,\y) -- (7.6,\y);
\draw[semithick,->] (8.4,\y) -- (9,\y) -- ($(9,\y)+(0,0.2)$) -- ($(9.2,\y)+(0,0.2)$) -- (9.2,\y) -- (10,\y);
}
% draw arc before array
\draw[semithick,dashed] (2,9.6) arc(0:-60:5.15);
% draw arc after array
\draw[semithick,dashed] (5.1,9.6) arc(0:-60:5.15);
% draw rectangle for digital adder
\draw[semithick] (10,9.5) -- (10.5,9.5) -- (10.5,5) -- (10,5) -- cycle;
\node[rotate=90] at (10.25,7.25) {\scriptsize Digital adder};
% draw output signal
\draw[semithick,] (10.5,7.25) -- (11,7.25) -- (11,7.75) -- (11.25,7.75) -- (11.25,7.25) -- (11.5,7.25);
\node[above] at (11.125,7.75) {\scriptsize$\begin{matrix}\text{Output}\\\text{signal}\end{matrix}$};
% draw arrow for sampling clock
\draw[semithick,->] (6.7,4.5) -- (6.7,5.05);
\node[below] at (6.7,4.5) {\scriptsize Sampling clock};
% draw line in between every ADC
\foreach \y in {5.25,5.75,...,8.75}
\draw[semithick] ($(6.7,\y)+(0,0.2)$) -- ($(6.7,\y)+(0,0.3)$);
\end{tikzpicture}
答案1
您可以使用intersections
库来实现这一点。要使用它,请使用 为要相交的路径命名name path
,然后使用 命名交叉点。然后交叉点将以、等形式intersections={of=<path 1> and <path 2>}
提供。intersection-1
intersection-2
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\def\pulse{+(0.1,0) -- +(0.2,0.1) -- +(0.3,-0.1) -- +(0.4,0)}
\draw[semithick,dashed,name path=arcafter] (5.1,9.6) arc(0:-60:5.15);
\foreach \y in {5.25,5.75,...,9.25}
{
\draw[semithick,->,name path=arrow] (2.25,\y) -- (5.5,\y);
\draw[name intersections={of=arcafter and arrow}] (intersection-1) ++(-0.2,0) \pulse;
}
\end{tikzpicture}
\end{document}