4

I would like to fill the portion which is bounded by two ellipses and two lines. The portion is indicated with "Here" in the figure. I tried multiclip with no success. Is there any simpler way?

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes, calc, fit, arrows.meta, arrows, patterns, 
positioning, intersections, 3d, matrix}
\usetikzlibrary{decorations.pathmorphing, decorations.shapes}

\begin{document}

\begin{tikzpicture}

    \draw (0,0) ellipse (2 and 1);
    \draw (0,0) ellipse (3 and 2);
    \draw (0,0) ellipse (4 and 3);
    \draw (0,1) -- (0,3);
    \draw (0,-1) -- (0,-3);
    \draw (2,0) -- (4,0);
    \draw (-2,0) -- (-4,0);
    \draw (1.36,0.75) -- (3.0,2);
    \draw (-1.36,0.75) -- (-3.0,2);
    \draw (1.36,-0.75) -- (3.0,-2);
    \draw (-1.36,-0.75) -- (-3.0,-2);        
    \node at (1,1.4){Here};

\end{tikzpicture}

\end{document}
0

3 Answers 3

4

Here are two solutions. In the first I combined a polygonal clip with an elliptical fill. In the second I computed the arc angles corresponding to the given points (actually, the intersection between them and the middle ellipse).

\documentclass[multi=tikzpicture]{standalone}% or just [tikz]

\usepackage{tikz}
\usetikzlibrary{shapes, calc, fit, arrows.meta, arrows, patterns, 
positioning, intersections, 3d, matrix}
\usetikzlibrary{decorations.pathmorphing, decorations.shapes}

\begin{document}

\begin{tikzpicture}
    \begin{scope}
      \clip (0,1) -- (0,3) -- (3,2) -- (1.36,0.75) -- cycle;
      \fill[pink, even odd rule] (0,0) ellipse (3 and 2) ellipse (2 and 1);
    \end{scope}
    \draw (0,0) ellipse (2 and 1);
    \draw (0,0) ellipse (3 and 2);
    \draw (0,0) ellipse (4 and 3);
    \draw (0,1) -- (0,3);
    \draw (0,-1) -- (0,-3);
    \draw (2,0) -- (4,0);
    \draw (-2,0) -- (-4,0);
    \draw (1.36,0.75) -- (3.0,2);
    \draw (-1.36,0.75) -- (-3.0,2);
    \draw (1.36,-0.75) -- (3.0,-2);
    \draw (-1.36,-0.75) -- (-3.0,-2);      
    \node at (1,1.4){Here};
\end{tikzpicture}

\begin{tikzpicture}
    \pgfmathsetmacro{\inner}{atan2(0.75,1.36/2)}%
    \path[name path=A] (0,0) ellipse (3 and 2);
    \path[name path=B] (1.36,0.75) -- (3.0,2);
    \path[name intersections={of=A and B, by=C}] (C);
    \pgfgetlastxy{\Cx}{\Cy}
    \pgfmathsetmacro{\outer}{atan2(\Cy/2,\Cx/3)}%

    \fill[pink] (0,1) -- (0,2) arc[x radius=3, y radius=2, start angle=90, end angle={\outer}]
                -- (1.36,0.75) arc[x radius=2, y radius=1, start angle={\inner}, end angle=90] -- cycle;

    \draw (0,0) ellipse (2 and 1);
    \draw (0,0) ellipse (3 and 2);
    \draw (0,0) ellipse (4 and 3);
    \draw (0,1) -- (0,3);
    \draw (0,-1) -- (0,-3);
    \draw (2,0) -- (4,0);
    \draw (-2,0) -- (-4,0);
    \draw (1.36,0.75) -- (3.0,2);
    \draw (-1.36,0.75) -- (-3.0,2);
    \draw (1.36,-0.75) -- (3.0,-2);
    \draw (-1.36,-0.75) -- (-3.0,-2);      
    \node at (1,1.4){Here};
\end{tikzpicture}

\end{document}
4

Here is an alternative to John Kormylo's answer. In this very case, this is not needed, but in general clip even odd rule can be very useful.

\documentclass{standalone}
\usepackage{tikz}
% see https://tex.stackexchange.com/a/359661/121799
\tikzset{clip even odd rule/.code={\pgfseteorule}}
\begin{document}
\begin{tikzpicture}
    \begin{scope}
     \clip[clip even odd rule] (0,0) ellipse (2 and 1) (0,0) ellipse (3 and 2);
     \fill[blue!20] (0,0) -- (0,3) -- (3,2) -- (1.36,0.75);
    \end{scope}

    \draw (0,0) ellipse (2 and 1);
    \draw (0,0) ellipse (3 and 2);
    \draw (0,0) ellipse (4 and 3);
    \draw (0,1) -- (0,3);
    \draw (0,-1) -- (0,-3);
    \draw (2,0) -- (4,0);
    \draw (-2,0) -- (-4,0);
    \draw (1.36,0.75) -- (3.0,2);
    \draw (-1.36,0.75) -- (-3.0,2);
    \draw (1.36,-0.75) -- (3.0,-2);
    \draw (-1.36,-0.75) -- (-3.0,-2);        
    \node at (1,1.4){Here};
\end{tikzpicture}
\end{document}

enter image description here

4

Here is a solution essentially based on a parametric representation of the two inner ellipses (though I used the ellipse node shape from shapes.geometric to draw the complete ellipses, which is the easiest part):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

% Define the start and end angles of the sector to be filled
\def\sectorStartAngle{45}
\def\sectorEndAngle{90}

% Allows scaling the ellipses
\def\myUnit{8em}

% Dimensions of the inner ellipse
\def\innerXDiameter{2}         % in \myUnit
\def\innerYDiameter{1}         % in \myUnit

% Dimensions of the middle ellipse
\def\middleXDiameter{3}        % in \myUnit
\def\middleYDiameter{2}        % in \myUnit

% Dimensions of the outer ellipse
\def\outerXDiameter{4}         % in \myUnit
\def\outerYDiameter{3}         % in \myUnit

\begin{document}
\begin{tikzpicture}[
  my ellipse/.style args={#1and #2}{%
    draw, color=blue, shape=ellipse, inner sep=0pt,
    minimum width={(#1)*\myUnit},minimum height={(#2)*\myUnit}}]
\node[my ellipse={\innerXDiameter and \innerYDiameter}] (inner) at (0,0) {};
\node[my ellipse={\middleXDiameter and \middleYDiameter}] (middle) at (0,0) {};
\node[my ellipse={\outerXDiameter and \outerYDiameter}] (outer) at (0,0) {};

% Parameter transformations for the two inner ellipses. These transformations
% allow one to specify the plot parameter in degrees as if we had a circle
% parametrization. Thanks to this, the start and end angles can be given in
% degrees below, instead of in some skewed approximation.
\def\innerParam{atan2(\innerXDiameter*sin(\theta), \innerYDiameter*cos(\theta))}
\def\middleParam{atan2(\middleXDiameter*sin(\theta), \middleYDiameter*cos(\theta))}

\fill[red!20, smooth, variable=\theta]
  plot[domain=\sectorStartAngle:\sectorEndAngle]
    ({0.5*\innerXDiameter*\myUnit*cos(\innerParam)},
     {0.5*\innerYDiameter*\myUnit*sin(\innerParam)})
  --
  plot[domain=\sectorEndAngle:\sectorStartAngle]
    ({0.5*\middleXDiameter*\myUnit*cos(\middleParam)},
     {0.5*\middleYDiameter*\myUnit*sin(\middleParam)})
  -- cycle;

\foreach \i in {0, ..., 7} {
  \draw[help lines] (node cs:name=inner, angle=45*\i) --
                    (node cs:name=outer, angle=45*\i);
}
\end{tikzpicture}
\end{document}

Screenshot

Note: there may be a way to simplify a little bit the definition of the path to be filled using the arc operation, however the following:

(node cs:name=inner, angle=\sectorStartAngle)
  arc[start angle=\sectorStartAngle, end angle=\sectorEndAngle,
      x radius=0.5*\innerXDiameter*\myUnit,
      y radius=0.5*\innerYDiameter*\myUnit]

does not give the first arc from my filled path above. Anyway, working with parametric plots as done above can be very helpful for other problems (it is “empowering“).

You must log in to answer this question.

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