如何识别两个圆之间的交点并为重叠区域着色?

如何识别两个圆之间的交点并为重叠区域着色?
\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

该包为您提供了一个用于计算两个圆的交点的tkz-euclide宏。因此,该行指定以 为圆心、半径为 1 厘米的圆和以 为圆心、半径为 1.5 厘米的圆将找到交点。该宏将交点命名为和。\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}

我也尝试过不使用 Intersections 库来做到这一点。第一个交叉点位于通往第二个中心的路径上。我尝试使用

\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

相关内容