2 つの円の交点を識別し、重なり合った領域を色分けするにはどうすればよいでしょうか?

2 つの円の交点を識別し、重なり合った領域を色分けするにはどうすればよいでしょうか?
\documentclass[12pt]{article}
\usepackage{geometry} 
\usepackage[T1]{fontenc}    
\usepackage[latin1]{inputenc}   
\usepackage[brazil]{babel} 
\usepackage{tikz}               
\begin{center}
\begin{document}
\begin{tikzpicture}
\draw[ultra thick](0,0) circle [radius=1];
\draw[ultra thick](1.5,0.5) circle [radius=1.5];
\end{tikzpicture}
\end{center}
\end{document}

ここに画像の説明を入力してください

答え1

このパッケージには、2 つの円の交点を計算するtkz-euclideマクロが含まれています。つまり、 の行は、 を中心とする半径 1 cm の円と を中心とする半径 1.5 cm の円の交点を見つけるように指定します。マクロは、交点に および という名前を付けます。\tkzInterCC\tkzInterCC[R](A,1 cm)(B,1.5 cm) \tkzGetPoints{M1}{N1}AB\tkzGetPoints{M1}{N1}M1N1

\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}

交差領域 (順序カウント) の後に円を描くと便利だと思います。Gummi の出力を以下に示します。

ここに画像の説明を入力してください

答え2

コメントにもあるように、重なり合う領域を埋めるのに交差点は必要ありません。ただし、交差点が必要な場合は、交差点ライブラリを使用して交差点を見つけることができます。以下のコードは、この例を示しています。

\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}

交差点ライブラリを使わずにこれをやってみました。最初の交差点は2番目の中心につながるパスにあります。2番目の交差点を次のようにして見つけようとしました。

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

しかし、LaTeX では不完全な \iffalse エラーが発生します。これを修正する方法を知っている人はいますか?


編集答えを見つけたここ\pgfmathparse を削除する必要があるので、交差ライブラリを使用しない別のソリューションが考えられます。

\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}

答え3

Alain が述べたように、intersections交差点を見つけるにはライブラリが選択肢になるかもしれません。

残りの円を背景色で塗りつぶしても構わない場合は、次のワンライナーで円の交差部分を塗りつぶすことができます。

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

まず、パス全体 (両方の円の結合) をハイライト カラーで塗りつぶし、次に ( を使用してpostaction) 残りの部分 (対称差) を背景色で再描画します ( を使用して) even odd rule

関連情報