교차하는 두 개의 모양이 주어지면 TikZ에서 공통 영역(즉, 교차점 사이의 영역)을 어떻게 채울 수 있습니까?
여기서는 even odd rule
대체 채우기가 아니라 교차점이므로 작동하지 않을 수 있습니다.
교차점을 결정하기 위해 라이브러리를 사용하고 있습니다 intersections
.
아래 MWE에서 C
과 사이의 영역을 어떻게 채우나요 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
공통 영역은 원 중 하나를 잘라내고 다른 원을 채워서 얻습니다.
\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}