TikZ で n 個の交差点の間の領域を塗りつぶす方法

TikZ で n 個の交差点の間の領域を塗りつぶす方法

交差する 2 つの図形がある場合、TikZ でそれらの図形に共通する領域 (つまり、交差点間の領域) をどのように塗りつぶすことができますか。

ここでは、even odd rule交互に塗りつぶすのではなく、交差する点であるため、機能しない可能性があります。

交差点を決定するために、intersectionsライブラリを使用していることに注意してください。

C以下の MWE で、との間の領域をどのように塗りつぶすのですかC'

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (1.25,0.25);


  \node (E) [name path=E,draw,circle through=(B)] at (A) {};
  \node (F) [name path=F,draw,circle through=(A)] at (B) {};

  \path [name intersections={of=E and F, by={[label=above:$C$]C,[label=below:$C'$]C'}}];


\end{tikzpicture}
\end{document}

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

答え1

共通領域は、円の 1 つを切り取り、もう 1 つを塗りつぶすことによって得られます。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through}
\makeatletter % from https://tex.stackexchange.com/a/127045/121799
\tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (1.25,0.25);


  \node (E) [name path=E,draw,circle through=(B),save path=\pathA] at (A) {};
  \node (F) [name path=F,draw,circle through=(A),save path=\pathB] at (B) {};
  \begin{scope}
  \clip[use path=\pathA];
  \fill[blue,use path=\pathB];
  \end{scope}

  \path [name intersections={of=E and F, by={[label=above:$C$]C,[label=below:$C'$]C'}}];


\end{tikzpicture}
\end{document}

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

円の輪郭が部分的に塗りつぶされることが気になる場合は、 を使用しますbackgrounds

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through,backgrounds}
\makeatletter % from https://tex.stackexchange.com/a/127045/121799
\tikzset{use path/.code=\tikz@addmode{\pgfsyssoftpath@setcurrentpath#1}}
\makeatother
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (1.25,0.25);


  \node (E) [name path=E,draw,circle through=(B),save path=\pathA] at (A) {};
  \node (F) [name path=F,draw,circle through=(A),save path=\pathB] at (B) {};
  \begin{scope}[on background layer]
  \clip[use path=\pathA];
  \fill[blue,use path=\pathB];
  \end{scope}

  \path [name intersections={of=E and F, by={[label=above:$C$]C,[label=below:$C'$]C'}}];


\end{tikzpicture}
\end{document}

交差セグメントはいつでも塗りつぶすことができます。(これを上記の背景と組み合わせることができます。)

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.16}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (1.25,0.25);


  \node (E) [name path=E,draw,circle through=(B)] at (A) {};
  \node (F) [name path=F,draw,circle through=(A)] at (B) {};

  \path [name intersections={of=E and F, by={[label=above:$C$]C,[label=below:$C'$]C'}}];

  \path[%draw,red,thick,
  fill=blue,
  intersection segments={of=E and F,sequence={L1--R2--L3}}];
\end{tikzpicture}
\end{document}

(上記と同じ出力です。)

弧の解析的決定も別の可能性です。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,through,calc}
\begin{document}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (1.25,0.25);


  \node (E) [name path=E,draw,circle through=(B)] at (A) {};
  \node (F) [name path=F,draw,circle through=(A)] at (B) {};

  \path [name intersections={of=E and F, by={[label=above:$C$]C,[label=below:$C'$]C'}}];
  \path[fill=blue] let \p1=($(A.center)-(B.center)$),\p2=($(C.center)-(A.center)$),
  \p3=($(C'.center)-(A.center)$),\p4=($(C.center)-(B.center)$),
  \p5=($(C'.center)-(B.center)$),
  \n1={veclen(\x2,\y2)}, % radius A
  \n2={veclen(\x4,\y4)}, % radius B
  \n3={atan2(\y2,\x2)}, % angle A 1
  \n4={atan2(\y3,\x3)}, % angle A 2
  \n5={atan2(\y4,\x4)}, % angle B 1
  \n6={atan2(\y5,\x5)} % angle B 2
  in (C) arc(\n3:\n4:\n1)  arc(\n6:\n5-360:\n2);

\end{tikzpicture}
\end{document}

関連情報