在 pgfmanual p 132 的这个示例中,如何使用\t
交点数外部\fill
命令。我试过了\def\Nb{\t}
,但没有用。
\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, name=i, total=\t}]
[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
答案1
您可以使用\pgfextra{\xdef\Nb{\t}}
或\pgfextra{\global\let\Nb\t}
:
\documentclass[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);
\path [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
\pgfextra{\xdef\Nb{\t}};
\fill [red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\Nb}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
\end{document}