6

In this examle from pgfmanual p 132, how to use \t the number of intersections point outside \fill command. I tried \def\Nb{\t} but it dosen't work.

\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}
8

You may use \pgfextra{\xdef\Nb{\t}} or \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}
| improve this answer | |
  • Possible also \pgfextra{\global\let\t\t} – Alain Matthes Feb 28 '14 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.