2

I need to:

  1. draw an ellipse,
  2. name it so I can intersect it later,
  3. clip it.

To accomplish 3, it seems most appropriate to use a scope, but this means that I cannot accomplish 2. Consider this MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
  \draw[->] (-2.0, 0.0) -- (2.0,0.0);
  \draw[->,name path=yaxis] ( 0.0,-2.0) -- (0.0,2.0);
  \draw[name path=ellipse] (-1.0,0.0) ellipse (1.5 and 0.6);
  \path[name intersections={of=ellipse and yaxis,by=x}];
  \draw[red,fill=red] (x) circle (1pt);
\end{tikzpicture}
\end{document} 

which gives

enter image description here

where the red circle indicates the intersection point. This accomplishes 1 and 2, but not 3, for which I would need something like

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
  \draw[->] (-2.0, 0.0) -- (2.0,0.0);
  \draw[->,name path=yaxis] ( 0.0,-2.0) -- (0.0,2.0);
  \begin{scope}
    \clip (-2.0,-2.0) rectangle (2.0,2.0);
    \draw[name path=ellipse] (-1.0,0.0) ellipse (1.5 and 0.6);
  \end{scope}
\end{tikzpicture}
\end{document}

giving

enter image description here

but due to the scope, I cannot refer to the path and determine the intersection point and draw it as a red circle.

So what is the best way to clip the ellipse but still be able to use it to determine an intersection point? Is there a way to make some "properties" from within a scope global?

5

Are you looking for name path global?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
  \draw[->] (-2.0, 0.0) -- (2.0,0.0);
  \draw[->,name path=yaxis] ( 0.0,-2.0) -- (0.0,2.0);
  \begin{scope}
    \clip (-2.0,-2.0) rectangle (2.0,2.0);
    \draw[name path global=ellipse] (-1.0,0.0) ellipse (1.5 and 0.6);
  \end{scope}
  \draw[name intersections={of=ellipse and yaxis,by=x},red,fill=red] (x) circle (1pt);
\end{tikzpicture}
\end{document}

enter image description here

  • Great, didn't expect such a quick resolution of my problem. I wonder why name path global is not mentioned in the manual where scope is explained. – user1362373 Sep 23 at 19:13
  • @user1362373 /tikz/name path global is mentioned on p. 142 of pgfmanual v3.1.4b, along with the warning "Handle with care". (So far I had no issues using it, but inside the library it is mentioned that "the name path global is not reset properly - and some following name path will append to it rather that reset it.".) – Schrödinger's cat Sep 23 at 20:24

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.