0

I am trying to remove a line (from an ellipse) when it crosses into the circle, but cant seem to get it to work:(

\begin{tikzpicture}
  \shade[ball color = gray!100, opacity = 0.4] (0,0) circle (2cm);
  \draw (0,0) circle (2cm);
  \draw (-2,0) arc (180:360:2 and 0.6);
  \draw[dashed] (2,0) arc (0:180:2 and 0.6);
  \fill[fill=black] (0,0) circle (1pt);
  \draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
  \def \firstellipse {(-1.5,0) ellipse (2 and 4)} 
  \draw[dashed] \firstellipse
\end{tikzpicture}

So to clarify, i want to remove the parts of the ellipsis that is within the borders of the circle!

Baloo
  • 1

2 Answers2

1

Well you could:

  • use a \clip just before the ellipse but this requires extra code, or better...

  • remove the opacity = 0.4 from the ellipse and change the color command (I assume you just want it lighter), from gray!1001 to gray!10, for example.

    Also, move the ellipse so it appears before the ball shape.

In the end it should be like this:

\draw[dashed] \firstellipse; % <-- also the semicolon was missing in your code
\shade[ball color = gray!10] (0,0) circle (2cm);

and the result is

enter image description here

1: By the way, gray!100 gives the same output as just gray.

Alenanno
  • 37,338
0

You can use an inverted clip. Notice that instead of \def you can use insert path to store a path in a macro or key.

\documentclass[tikz,border=3mm]{standalone}
% https://tex.stackexchange.com/a/59168
\tikzset{reverseclip/.style={overlay,insert path={[reset cm]
      (-16383.99999pt,-16383.99999pt) rectangle
      (16383.99999pt,16383.99999pt)}}}
\begin{document}
\begin{tikzpicture}[c/.style={insert path={(0,0) circle[radius=2]}},
    e/.style={insert path={(-1.5,0) circle[x radius=2,y radius=4]}}]
  \draw[ball color = gray!100,fill opacity = 0.4,c];
  \draw (-2,0) arc[start angle=180,end angle=360,x radius=2,y radius=0.6];
  \draw[dashed] (2,0) arc[start angle=0,end angle=180,x radius=2,y radius=0.6];
  \fill[fill=black] (0,0) circle (1pt);
  \draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
  \clip[c,reverseclip];
  \draw[overlay=false,dashed,e];
\end{tikzpicture}
\end{document}

enter image description here