# How to identify the points of intersection between two circles and coloring the overlapped area?

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[brazil]{babel}
\usepackage{tikz}
\begin{center}
\begin{document}
\begin{tikzpicture}
\end{tikzpicture}
\end{center}
\end{document} • Nov 15 '16 at 14:51
• Marijn - The problem cited paints the common region but not explicitly how to calculate the points of intersection Nov 15 '16 at 15:00
• this is an example in the manual page 139 of version 3.0.1.a Nov 15 '16 at 15:05
• Can you clarify what exactly you need? I assumed you thought you needed to calculate the points in order to colour the overlap. Right now, your actual question consists entirely of code. Please tell us what exactly you are trying to do.
– cfr
Nov 15 '16 at 15:44

The tkz-euclide package gives you a macro \tkzInterCC for calculating the intersection points of 2 circles. So the line \tkzInterCC[R](A,1 cm)(B,1.5 cm) \tkzGetPoints{M1}{N1} specifies that the radius of circle centered at A with radius 1 cm and circle centered at B with radius 1.5cm will find the intersection points. The macro \tkzGetPoints{M1}{N1} names the intersection points as M1 and N1.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}%IMPORTANT--recognizes points, lines, circles, etc
\begin{document}
\begin{tikzpicture}[scale=1]
\tkzDefPoint(0,0){A}  %center of circle 1
\tkzDefPoint(1.5,0.5){B}  %center of circle 2
\tkzInterCC[R](A,1 cm)(B,1.5 cm) \tkzGetPoints{M1}{N1} %get the intersection
% of circles centered at A with radius 1 and B with radius 1.5 and store as M1, N1
\begin{scope}
\tkzClipCircle(A,M1)
\tkzFillCircle[color=green!50,opacity=.5](B,M1)
\end{scope}
\tkzDrawCircle[R](A,1.cm) %draw circle 1 centered at A with radius 1
\tkzDrawCircle[R](B,1.5cm) %draw circle 2 centered at B with radius 1
\tkzDrawPoints[color=orange, fill=orange](M1,N1)%Draw points
\end{tikzpicture}
\end{document}


I find it useful to draw the circles after the region of intersection (order counts). The output in Gummi is shown below: As said in the comment, you don't need the points of intersections to fill the overlapping area. But if you do need them, you could use the intersections library to find them. The code below shows an example of this.

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[brazil]{babel}
\usepackage{tikz}
\usetikzlibrary{intersections}

\def\rayona{1}
\def\rayonb{1.5}
\def\interangle{90}

\begin{document}
\begin{tikzpicture}

% define first center
\coordinate (centera) at (0,0);

% Calculate second center based on radius and where is first intersection
\draw (centera) ++ (\interangle:\rayona) ++ (\interangle-90:\rayonb) coordinate (centerb);

% fill in first
\begin{scope}
\clip (centera) circle (\rayona);
\fill[black!15] (centerb) circle (\rayonb);
\end{scope}

% then draw the circles
\draw[ultra thick,name path=circlea] (centera) circle (\rayona);
\draw[ultra thick,name path=circleb] (centerb) circle (\rayonb);

%find intersections
\draw[name intersections = {of = circlea and circleb}] (intersection-1) node[red] {$\times$} node[above left]{Inter1} (intersection-2) node[red] {$\times$} node[below right]{Inter2};
\end{tikzpicture}
\end{document}


I also tried to do this without the intersections library. The first intersections is found in the path leading to the second center. I tried to find the second one using

\draw (centera) ++ ({\pgfmathparse{\interangle-2*atan{\rayonb/\rayona}}\pgfmathresult}:\rayona) coordinate (inter2);


but latex gives me an incomplete \iffalse error. If anyone knows how to fix this?

Edit found my answer here The \pgfmathparse needs to be remove so an other solution could be, without the intersections library

\documentclass[12pt]{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[brazil]{babel}
\usepackage{tikz}

\def\rayona{1}
\def\rayonb{1.5}
\def\interangle{90}

\begin{document}
\begin{tikzpicture}

% define first center
\coordinate (centera) at (0,0);

% Calculate second center based on radius and where is first intersection and define the first intersection
\draw (centera) ++ (\interangle:\rayona) coordinate (inter1) ++ (\interangle-90:\rayonb) coordinate (centerb);

% fill in first
\begin{scope}
\clip (centera) circle (\rayona);
\fill[black!15] (centerb) circle (\rayonb);
\end{scope}

% then draw the circles
\draw[ultra thick] (centera) circle (\rayona);
\draw[ultra thick] (centerb) circle (\rayonb);

%calculate the position of the second intersection
\draw (centera) ++ ({\interangle-2*atan{\rayonb/\rayona}}:\rayona) coordinate (inter2);;

% Use intersection
\draw (inter1) node[red] {$\times$} node[above left] {Inter1};
\draw (inter2) node[red] {$\times$} node[below right] {Inter2};
\end{tikzpicture}
\end{document}


As mentioned by Alain, the intersections library may be your choice for finding the intersection points.

If you dont mind having the rest of your circles filled with the background color, filling the circles' intersection can be done with this one-liner:

\path[fill=yellow, postaction={fill=white, even odd rule, draw}] (0,0) circle (2) (2,.3) circle (3);


First fill the whole path (union of both circles) with your highlight color, then (using postaction) redraw the rest (symmetric difference) with your background color, using even odd rule.