1

I have two circles whose intersecting area is occupied by an ellipse. I need to do:

  1. Draw a vertical line dividing the ellipse.
  2. Shade the four areas from the intersection of ellipse with the circles differently.

I have the plots here, can someone help me with the shading?

\documentclass[]{article}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{arrows, automata, arrows.meta, positioning, calc}

\begin{document}
\begin{figure*}[h]
\centering
\begin{tikzpicture}[scale=2]
\draw (0,0) circle (1 cm) (1.1,0) circle (0.8 cm);
\draw (0.5,0) circle (0.8 cm and 0.3 cm);
\end{tikzpicture}
\end{figure*}
\end{document}

enter image description here

  • Please, a complete (compilable) example is better than only code fragments. – Ignasi Apr 20 '16 at 17:21
  • Please use some graphic example (paint by hand is enough) to show, what you mean. – MaestroGlanz Apr 20 '16 at 17:47
4

Here is another suggestion using TikZ:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}

\tikzset{
  reverseclip/.style={% see http://tex.stackexchange.com/a/12033/43317
    insert path={(current page.north east) --
      (current page.south east) --
      (current page.south west) --
      (current page.north west) --
      (current page.north east)
}}}

\begin{document}
\begin{tikzpicture}[scale=2]

\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\newcommand\circleI[1][]{
  \path[#1](0,0) circle [radius=1cm]}
\newcommand\circleII[1][]{
  \path[#1] (1.1,0) circle [radius=.8cm]}
\newcommand\ellipse[1][]{
  \path[#1] (0.5,0) circle [x radius=0.8 cm,y radius= 0.3 cm]}

\circleI[draw];
\circleII[draw];
\ellipse[draw]
  (current path bounding box.north)coordinate(s1)
  --
  (current path bounding box.south)coordinate(s2)
;

\pgfonlayer{pre main}
  \begin{scope}[overlay]
    \circleI[clip][reverseclip];
    \ellipse[fill=orange!20];
  \end{scope}

  \begin{scope}[overlay]
    \circleII[clip][reverseclip];
    \ellipse[fill=purple!20];
  \end{scope}

  \begin{scope}[overlay]
    \circleI[clip]
      (current path bounding box.west)coordinate(h1)
    ;
    \circleII[clip]
        (current path bounding box.east)coordinate(h2)
    ;
    \begin{scope}
      \path[clip](s1-|h1)rectangle(s2);
      \ellipse[fill=blue!20];
    \end{scope}
    \begin{scope}
      \path[clip](s1-|h2)rectangle(s2);
      \ellipse[fill=green!20];
    \end{scope}
  \end{scope}
\endpgfonlayer
\end{tikzpicture}
\end{document}

enter image description here

It is also possible to use patterns.

enter image description here

Code:

\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\tikzset{
  reverseclip/.style={% see http://tex.stackexchange.com/a/12033/43317
    insert path={(current page.north east) --
      (current page.south east) --
      (current page.south west) --
      (current page.north west) --
      (current page.north east)
}}}

\begin{document}
\begin{tikzpicture}[scale=2,pattern color=gray]

\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\newcommand\circleI[1][]{
  \path[#1](0,0) circle [radius=1cm]}
\newcommand\circleII[1][]{
  \path[#1] (1.1,0) circle [radius=.8cm]}
\newcommand\ellipse[1][]{
  \path[#1] (0.5,0) circle [x radius=0.8 cm,y radius= 0.3 cm]}

\circleI[draw];
\circleII[draw];
\ellipse[draw]
  (current path bounding box.north)coordinate(s1)
  --
  (current path bounding box.south)coordinate(s2)
;

\pgfonlayer{pre main}
  \begin{scope}[overlay]
    \circleI[clip][reverseclip];
    \ellipse[pattern=north east lines];
  \end{scope}

  \begin{scope}[overlay]
    \circleII[clip][reverseclip];
    \ellipse[pattern=dots];
  \end{scope}

  \begin{scope}[overlay]
    \circleI[clip]
      (current path bounding box.west)coordinate(h1)
    ;
    \circleII[clip]
        (current path bounding box.east)coordinate(h2)
    ;
    \begin{scope}
      \path[clip](s1-|h1)rectangle(s2);
      \ellipse[pattern=horizontal lines];
    \end{scope}
    \begin{scope}
      \path[clip](s1-|h2)rectangle(s2);
      \ellipse[pattern=fivepointed stars];
    \end{scope}
  \end{scope}
\endpgfonlayer
\end{tikzpicture}
\end{document}
3

Here is an approach using tikz:

EDIT

Simplified the code a little by making use of the even odd rule.

EDIT2

Just for fun a second, little more minimalistic solution using the mixing of colours.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{patterns}
%
\begin{document}
%
\begin{tikzpicture}
    %
    \def\ellipse{(1,0) circle (1.6 cm and 0.6 cm)}%
    \def\circone{(0,0) circle (2 cm)}%
    \def\circtwo{(2.2,0) circle (1.6 cm)}%
    \def\rectone{ (1.3,1) rectangle ++(2,-2)}%
    \def\recttwo{ (1.3,1) rectangle ++(-2,-2)}%
    %
    \begin{scope}[even odd rule]
        \clip \circone \rectone \recttwo;
        \pattern[pattern=dots, pattern color=gray] \ellipse;
    \end{scope}
    %
    \begin{scope}[even odd rule]
        \clip \circtwo \rectone \recttwo;
        \pattern[pattern=crosshatch, pattern color=gray] \ellipse;
    \end{scope}
    %
    \begin{scope}
        \clip \circone;
        \clip \rectone;
        \pattern[pattern=checkerboard, pattern color=gray] \ellipse;
    \end{scope}
    %
    \begin{scope}
        \clip \circtwo;
        \clip \recttwo;
        \pattern[pattern=fivepointed stars, pattern color=gray] \ellipse;
    \end{scope}
    %
    \begin{scope}
        \clip \ellipse;
        \draw[thick] \recttwo;  
    \end{scope}
    %
    \draw \circone \circtwo \ellipse;
    %
\end{tikzpicture}%
%
\end{document}

enter image description here

\documentclass[tikz, border=2mm]{standalone}
%
\begin{document}
%
\begin{tikzpicture}
    %
    \def\ellipse{(1,0) circle (1.6 cm and 0.6 cm)}%
    \def\circone{(0,0) circle (2 cm)}%
    \def\circtwo{(2.2,0) circle (1.6 cm)}%
    \def\rect{ (1.3,1) rectangle ++(-2,-2)}%
    %
    \fill[yellow] \ellipse;
    %
    \begin{scope}
        \clip \rect;
        \fill[red] \ellipse;
    \end{scope}
    %
    \begin{scope}
        \clip \circtwo;
        \clip \circone;
        \fill[blue, opacity=0.5] \ellipse;
    \end{scope}
    %
    \begin{scope}
        \clip \ellipse;
        \draw[thick] \rect; 
    \end{scope}
    %
    \draw \circone \circtwo \ellipse;
    %
\end{tikzpicture}%
%
\end{document}

enter image description here

2

A job for Metapost + luamplib with buildcycle.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
    beginfig(1);
      path C, c, e, m;
      C = fullcircle scaled 5cm rotated 180 shifted (-2cm,0);
      c = fullcircle scaled 3cm shifted (1cm,0);
      e = fullcircle xscaled 4cm yscaled 1cm;
      m = point 6 of e -- point 2 of e;

      path a[];
      a1 = buildcycle(c, subpath (6,2) of e);
      a2 = buildcycle(c, subpath (5,6) of e, m, subpath (2,3) of e); 
      a3 = buildcycle(C, subpath (1,2) of e, m, subpath (6,7) of e);                
      a4 = buildcycle(C, subpath (2,0) of e, subpath (8,6) of e);

      fill a1 withcolor .8[red,white];
      fill a2 withcolor .8[red+green,white];
      fill a3 withcolor .8[green+blue,white];
      fill a4 withcolor .8[blue,white];

      draw C;
      draw c;
      draw e;
      draw m;
    endfig;
\end{mplibcode}
\end{document}

You can, of course, fill with patterns if you prefer; but you have to draw a region of the pattern and then clip it to the shape rather than filling directly.

  • Hi Your code does not work for me. I get a "Undefined control sequence RequireLuAModule" error. – Bravo Apr 21 '16 at 7:52
  • 1
    @Bravo If you follow the links at the top of my answer you can find out how to run luamplib. You can either: Run it as I've posted it with lualatex; or remove the latex wrapping code and run it with mpost. See the links for full explanations. – Thruston Apr 21 '16 at 9:18

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.