New MembersColoring Intersected Circles

You would like to introduce yourself before starting to post? That's a nice idea and here is the forum for you...
Post Reply
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Coloring Intersected Circles

Post by asmithb »

Dear Latex Members,
I would like to know how to depict diagonal-dashed lines on the place of the white area where the 3 circles intersect.

Here I attach the codes so you see the three circles:

Code: Select all

 
 \begin{figure}
    \centering
    \caption{Absorption of Veto Player B}
    \label{fig:my_label}

\begin{tikzpicture}


 
\begin{scope} [fill opacity = .4]
 
\draw (-8,5) rectangle (6,-5) ;
\draw[help lines](-8,5) grid (6,-5);
% name the paths:
\path[name path=A, draw, fill=green] (-4.5,0) circle (3) node(NA){};
\path[name path=C, draw, fill=red] (1.5,0) circle (4) node(NC){};
\path[name path=B, draw, fill=blue] (-1,0) circle (2) node(NB){};

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NA) circle (3);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[blue] (NB) circle (2);% same here for circle A

\end{scope}% end the scope to be able to draw something outside its clip area



\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NC) circle (4);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[blue] (NB) circle (2);% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NC) circle (4);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[white] (NA) circle (3);% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area

 
% get the intersection points between circles A and B:
\path[name intersections={of=A and C}];
\begin{scope}[fill opacity=0]% put some solid dots at the intersecting points:
\fill (intersection-2) circle (3pt) node[below=3pt]{SQ};
\end{scope}
 
\node at (-4,4) {\LARGE\textbf{A}};
\node at (3,4) {\LARGE\textbf{C}};
\end{scope}

% Point a
 \coordinate (a) at (-4.5,0);
 \fill (a) circle [radius=3pt];
 \node [below] at (a) {$A$}; 
 
 % Point b
 \coordinate (b) at (-1,0);
 \fill (b) circle [radius=3pt];
 \node [below] at (b) {$B$}; 


% Point c
 \coordinate (c) at (1.5,0);
 \fill (c) circle [radius=3pt];
 \node [below] at (c) {$C$}; 

\draw (a) -- (b); 
\draw (a) -- (c);  

\node at ([yshift=-7mm]  current bounding box.south)     
{
\begin{tabular}{r@{: }l r@{: }l}
$Green$ & Veto Player A Indifference Curve & $Blue& Veto Player B Indifference Curve & Pink& Veto Player C Indifference Curve &
$SQ& Status Quo &  $White& Winset Area of A-C = Winset Area of A-B-C //

\end{tabular}


};
\draw[help lines](-5,5) grid (5,-3);    
\end{tikzpicture}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Coloring Intersected Circles

Post by Bartman »

Unfortunately this is not a Infominimal working example.

You can use the options preaction or postaction to draw the required lines in the white area.

If the third circle should also participate in the limitation of the area, as I conclude from your description, then the second \clip command should be added.

Code: Select all

\clip (NB) circle (2);
% Needs to load the patterns library.
\fill[white, dashed, postaction={pattern=north west lines}] (NA) circle (3);
%\draw[preaction={fill=white}, dashed, pattern=north west lines] (NA) circle (3);
Instead of designing the legend using a table environment, I'd like to show an alternative using the matrix offered by TikZ.

Code: Select all

% Needs to load the matrix library.
\matrix[
  matrix of nodes,
  every odd column/.style={anchor=base east, font=\itshape},
  every even column/.style={anchor=base west},
  anchor=north
] at (current bounding box.south) {
  Green: & Veto Player A Indifference Curve & Blue: & Veto Player B Indifference Curve\\
  Pink:  & Veto Player C Indifference Curve & SQ:   & Status Quo\\
  White: & Winset Area of A-C = Winset Area of A-B-C\\
};
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Coloring Intersected Circles

Post by asmithb »

Dear Bartman,

I am writing \begin{matrix} and \end{matrix} but I do not manage to see the legend. Is this what you mean by the matrix library? I also loaded the amsmath package. Thanks for your support.
Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Coloring Intersected Circles

Post by Bartman »

My source code snippet needs neither the matrix environment nor the amsmath (or mathtools) package. The matrix I mentioned is dealt with in several sections of the TikZ documentation. You are already working with other libraries of the TikZ package, matrix is just one more.

Please start a new topic if you want to use one or my TikZ matrix for your legend and problems arise.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Coloring Intersected Circles

Post by Stefan Kottwitz »

This shows why it's good to post minimal working examples, as Bartman said. ;-)

The code by Bartman completed would be

Code: Select all

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
  \matrix[
    matrix of nodes,
    every odd column/.style={anchor=base east, font=\itshape},
    every even column/.style={anchor=base west},
    anchor=north
  ] at (current bounding box.south) {
    Green: & Veto Player A Indifference Curve & Blue: & Veto Player B Indifference Curve\\
    Pink:  & Veto Player C Indifference Curve & SQ:   & Status Quo\\
    White: & Winset Area of A-C = Winset Area of A-B-C\\
  };
\end{tikzpicture}
\end{document}
Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Coloring Intersected Circles

Post by Stefan Kottwitz »

And your code (completed to be a testable example) plus the suggestion by Bartman would be:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,matrix}
\usepackage{amsmath}

\begin{document} 
 \begin{figure}
    \centering
    \caption{Absorption of Veto Player B}
    \label{fig:my_label}

\begin{tikzpicture}
\begin{scope} [fill opacity = .4]
\draw (-8,5) rectangle (6,-5) ;
\draw[help lines](-8,5) grid (6,-5);
% name the paths:
\path[name path=A, draw, fill=green] (-4.5,0) circle (3) node(NA){};
\path[name path=C, draw, fill=red] (1.5,0) circle (4) node(NC){};
\path[name path=B, draw, fill=blue] (-1,0) circle (2) node(NB){};

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NA) circle (3);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[blue] (NB) circle (2);% same here for circle A

\end{scope}% end the scope to be able to draw something outside its clip area

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NC) circle (4);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[blue] (NB) circle (2);% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NC) circle (4);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[white] (NA) circle (3);% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area

 
% get the intersection points between circles A and B:
\path[name intersections={of=A and C}];
\begin{scope}[fill opacity=0]% put some solid dots at the intersecting points:
\fill (intersection-2) circle (3pt) node[below=3pt]{SQ};
\end{scope}
 
\node at (-4,4) {\LARGE\textbf{A}};
\node at (3,4) {\LARGE\textbf{C}};
\end{scope}

% Point a
 \coordinate (a) at (-4.5,0);
 \fill (a) circle [radius=3pt];
 \node [below] at (a) {$A$}; 
 
 % Point b
 \coordinate (b) at (-1,0);
 \fill (b) circle [radius=3pt];
 \node [below] at (b) {$B$}; 


% Point c
 \coordinate (c) at (1.5,0);
 \fill (c) circle [radius=3pt];
 \node [below] at (c) {$C$}; 

\draw (a) -- (b); 
\draw (a) -- (c);  

%\node at ([yshift=-7mm]  current bounding box.south)     
  \matrix at ([yshift=-7mm]  current bounding box.south) [
    matrix of nodes,
    every odd column/.style={anchor=base east, font=\itshape},
    every even column/.style={anchor=base west},
    anchor=north
  ] at (current bounding box.south) {
    Green: & Veto Player A Indifference Curve & Blue: & Veto Player B Indifference Curve\\
    Pink:  & Veto Player C Indifference Curve & SQ:   & Status Quo\\
    White: & Winset Area of A-C = Winset Area of A-B-C\\
  };
\draw[help lines](-5,5) grid (5,-3);    
\end{tikzpicture}
\end{figure}
\end{document}
If you now click on "Run LaTeX here" you can see the result.

That's actually a main reason why we like complete examples here: by one click, we can test it, and we can fix issues and improve it easily. That's why in your other recent thread our fellow users suggested that your code snippet should be compilable. Don't worry, that means compilable in theory ;-) just somehow complete, because if there's an error in the code (such as when the question is about an error) we can find it that way.

Stefan
LaTeX.org admin
Post Reply