TikZ 交叉點中選項「by」的意思是什麼

TikZ 交叉點中選項「by」的意思是什麼

PGF 手冊的第 65 頁顯示了intersectionsTikZ 中庫的不同操作。但我無法理解程式碼。這裡的選項是什麼意思by

在此輸入影像描述

給出的解釋是:

名稱交集採用可選參數 by,它允許您指定座標的名稱及其選項。這會創建更緊湊的程式碼。

這還不清楚。

答案1

相關行是

\path [name intersections={of=D and E, by={[label=above:$C$]C, [label=below:$C’$]C’}}];

與這個更簡單的版本進行比較:

\path [name intersections={of=D and E, by={C, C’}}];

這裡計算交點並命名為 C 和 C' ("姓名路口D 和 E 的 經過名字CC'”)。

它的快捷方式是

\coordinate (C) at ...;
\coordinate (C') at ...;

對於一些計算的座標。

新增可選樣式[label=above:$C$]C相當於

\coordinate[label=above:$C$] (C) at ...;

並允許您直接設定交叉點的樣式。儘管更長,但等效的寫法是

\path [name intersections={of=D and E, by={C, C’}}];
\node[above] at (C) {$C$};
\node[below] at (C') {$C'$};

答案2

只是為了完整性。您C-1只需使用即可透過等命名交叉點name=C。也許也值得指出的是,如果您想沿著直線對交叉點進行排序,那麼你必須畫出一條直線,假裝它是一條曲線

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
    \draw[name path=grid] [xstep=3,ystep=2] (9,8) grid (0,0);
    \draw[->, name path=line] (2,1) to[bend left=0] (7,7);
    \draw[name intersections={of=grid and line, sort by=line, name=C, total=\t}]
        \foreach \s in {1,...,\t}{(C-\s) node {\s}};
\end{tikzpicture}
\end{document}

在此輸入影像描述

答案3

預設情況下,交叉點被命名為(intersection-1)(intersection-2)等。

當你寫的時候,by={a,b}前兩個交點將被稱為(a)(b)

讓我們來看看第 142 頁的範例,稍加修改。它顯示兩條曲線的 9 個交點。交叉點總數由 給出total

透過編寫by={a,b},前 2 個交叉點現在有兩個名稱:

  • (a)或者(intersection-1)
  • (b)或者(intersection-2)

(a)是 的別名(intersection-1),其他的沒有別名並且仍然可以訪問。

螢幕截圖

\documentclass[border=5mm,tikz]{standalone}

\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
\clip (-2,-2) rectangle (2,2);
\draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);
\fill [name intersections={of=curve 1 and curve 2, by={a,b}, total=\t}]
[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(intersection-\s) circle (2pt) node {\footnotesize\s}};
\draw[fill=blue!50,opacity=.5] (a) circle (4pt);
\end{tikzpicture}
\end{document}

相關內容