4

Using the minimal working example below I've been able to make this image with tikzpicture: ![enter image description here

I would like to shade in the regions between the circle and the two outer elipses like this:

enter image description here

Using Graphing y=x^2 and y=x it's possible to do this in a slightly botched solution by first filling between the two ellipses and then filling in the remaining area between the circle and the vertical line created by filling in the ellipses. This feels like it is not "best practice". Is there a more clever way to do this?

Here is the minimal working example use to generate the first image

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%draw the circle
\draw (0,0) circle(1);    
\draw[fill] (0,1) circle [radius =0.05];
\draw[fill] (0,-1) circle [radius =0.05];
\draw plot[domain=pi:2*pi] ({cos(\x r)},{.2*sin(\x r)});
\draw[dashed] plot[domain=0:pi] ({cos(\x r)},{.2*sin(\x r)});

%draw the upper ellipse
\draw plot[domain=pi:2*pi] ({0.864*cos(\x r)},{.2*sin(\x r)+.5});
\draw[dashed] plot[domain=0:pi] ({0.864*cos(\x r)},{.2*sin(\x r)+.5});

%draw the lower ellipse
\draw plot[domain=pi:2*pi] ({0.864*cos(\x r)},{.2*sin(\x r)-.5});
\draw[dashed] plot[domain=0:pi] ({0.864*cos(\x r)},{.2*sin(\x r)-.5});
\end{tikzpicture}
\end{document}
1
  • Using trig functions to draw your ellipses is not the best idea, in my opinion. You could draw them with simple TikZ ellipses. Then use some clips to fill in.
    – SebGlav
    Commented Sep 4, 2022 at 16:42

1 Answer 1

4

As stated in my comment, using ellipses and clips seems easier to me.

shading into a sphere

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}


\begin{tikzpicture}
    \draw (0,0) circle[radius=2];
    
    %fills
    \fill[blue,opacity=0.2] (0,1) ellipse[x radius=1.72,y radius=0.4];
    \begin{scope}
        \clip (0,0) circle[radius=2];
        \fill [blue,opacity=0.6] (-1.72,1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4] -- (2,1) |- (1.72,-1) arc[start angle = 0, end angle = -180,x radius=1.72,y radius=0.4] -- (-2,-1) |- cycle;
    \end{scope}
    
    
    % Upper ellipse
    \draw (-1.72,1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4];
    \draw[dashed] (-1.72,1) arc[start angle = 180, end angle = 0,x radius=1.72,y radius=0.4];
    
    % Middle ellipse
    \draw (-2,0) arc[start angle = -180, end angle = 0,x radius=2,y radius=0.5];
    \draw[dashed] (-2,0) arc[start angle = 180, end angle = 0,x radius=2,y radius=0.5];
    
    % Lower ellipse
    \draw (-1.72,-1) arc[start angle = -180, end angle = 0,x radius=1.72,y radius=0.4];
    \draw[dashed] (-1.72,-1) arc[start angle = 180, end angle = 0,x radius=1.72,y radius=0.4];
    
    % Dots
    \filldraw   (0,2) circle [radius =0.05]
                (0,-2) circle [radius =0.05];
\end{tikzpicture}
\end{document}
2
  • 2
    Thanks alot, this is much cleaner! I don't have enough reputation for my upvote to appear on your answer but this solution is much appreciated!
    – Ryan Quinn
    Commented Sep 4, 2022 at 17:38
  • You're welcome ;)
    – SebGlav
    Commented Sep 4, 2022 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .