다항식과 다른 도형의 교차점 채우기

다항식과 다른 도형의 교차점 채우기

다항식으로 정의된 다양한 영역이 있는 교과서의 다이어그램을 다시 만들려고 합니다. 이상적으로는 어울리는 텍스트와 일치하도록 올바른 색상으로 채우고 싶습니다.

5개의 '모양'을 만들고 채울 수는 있지만 다른 영역(중앙 원 제외)을 다시 채우지 않고는 배경의 나머지 부분을 채울 수 없습니다.

이를 수행하는 (쉬운) 방법이 있습니까? 아니면 다이어그램을 완전히 다시 생각해야 합니까?

\documentclass[tikz,border=12pt,svgnames]{standalone}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,x=0.5cm,y=0.5cm,thin,samples=100,fill opacity=0.5]
\draw[help lines,step=0.5cm] (0,0) grid (14,8);
\draw[fill=red,domain=0:5] plot(\x,{-(1/3)*(\x+1)*(\x-5)}) |- (5,0) -- (0,0) -- cycle;
\draw[fill=Green,domain=10:14] plot(\x,{((\x-12)^3)/4+2}) |- (14,0) -- (10,0) -- cycle;
\draw[fill=Blue,domain=0:4] plot(\x,{((\x-2)^3)/4+6}) |- (4,8) -- (0,8) -- cycle;
\draw[fill=black,domain=9:14] plot(\x,{(\x-9)*(\x-15)/3+8}) |- (14,8) -- (9,8) -- cycle;
\draw[fill=Green,domain=9:14] (7,4) circle (3);
\draw[fill=pink,even odd rule,domain=9:14] (0,0) rectangle (14,8) (7,4) circle (3);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

답변1

플롯/배경 레이어를 불투명하게 만든 다음 눈금선 위에 그룹으로 투명하게 만들 수 있습니다.

결과

결과2

암호

\documentclass[tikz,border=12pt,svgnames]{article}

\usepackage{tikz}
\newsavebox{\myimagebox}

\begin{document}


% Save top layer in a box
% Composed as opaque layer, then made transparent as a group
\savebox{\myimagebox}{%
\begin{tikzpicture}[line cap=round,line join=round,x=0.5cm,y=0.5cm,thin,samples=100,transparency group,opacity=.5]
\draw[fill=pink,even odd rule,domain=9:14] (0,0) rectangle (14,8) (7,4) circle (3);
\draw[fill=red,domain=0:5] plot(\x,{-(1/3)*(\x+1)*(\x-5)}) |- (5,0) -- (0,0) -- cycle;
\draw[fill=Green,domain=10:14] plot(\x,{((\x-12)^3)/4+2}) |- (14,0) -- (10,0) -- cycle;
\draw[fill=Blue,domain=0:4] plot(\x,{((\x-2)^3)/4+6}) |- (4,8) -- (0,8) -- cycle;
\draw[fill=black,domain=9:14] plot(\x,{(\x-9)*(\x-15)/3+8}) |- (14,8) -- (9,8) -- cycle;
\draw[fill=Green,domain=9:14] (7,4) circle (3);
\end{tikzpicture}%
}

% Layer top over the grid lines
\begin{tikzpicture}[line cap=round,line join=round,x=0.5cm,y=0.5cm,thin,samples=100]
\draw[help lines,step=0.5cm] (0,0) grid (14,8);
\node[inner sep=0pt] (s) at (7,4){\usebox\myimagebox};
% Repeat these to highlight the black outlines again.
\draw[even odd rule,domain=9:14] (0,0) rectangle (14,8) (7,4) circle (3);
\draw[domain=0:5] plot(\x,{-(1/3)*(\x+1)*(\x-5)}) |- (5,0) -- (0,0) -- cycle;
\draw[domain=10:14] plot(\x,{((\x-12)^3)/4+2}) |- (14,0) -- (10,0) -- cycle;
\draw[domain=0:4] plot(\x,{((\x-2)^3)/4+6}) |- (4,8) -- (0,8) -- cycle;
\draw[domain=9:14] plot(\x,{(\x-9)*(\x-15)/3+8}) |- (14,8) -- (9,8) -- cycle;
\draw[domain=9:14] (7,4) circle (3);

\end{tikzpicture}

\end{document}

답변2

또 다른 방법이 있습니다. 곡선 외부를 채운 다음 중앙 원을 역자릅니다.

\documentclass[tikz,border=12pt,svgnames]{standalone}
\tikzset{
  invclip/.style={
    clip,
    insert path={{[reset cm] (-16000pt,-16000pt) rectangle (16000pt,16000pt)}}},
  saveuse path/.code 2 args={
    \pgfkeysalso{#1/.estyle={insert path={#2}}}%
    \global\expandafter\let\csname pgfk@\pgfkeyscurrentpath/.@cmd\expandafter\endcsname 
                           \csname pgfk@\pgfkeyscurrentpath/.@cmd\endcsname
    \pgfkeysalso{#1}}}
\def\invclip#1;{\pgfinterruptboundingbox\path[invclip]#1;\endpgfinterruptboundingbox}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,x=0.5cm,y=0.5cm,thin,samples=100,fill opacity=0.5]
\draw[help lines,step=0.5cm] (0,0) grid (14,8);
\draw[fill=red,domain=0:5] plot(\x,{-(1/3)*(\x+1)*(\x-5)})  |- (5,0) -- (0,0) -- cycle;
\draw[fill=Green,domain=10:14]  plot(\x,{((\x-12)^3)/4+2})  |- (14,0) -- (10,0) -- cycle;
\draw[fill=Blue,domain=0:4] plot(\x,{((\x-2)^3)/4+6}) |- (4,8) -- (0,8) -- cycle;
\draw[fill=black,domain=9:14] plot(\x,{(\x-9)*(\x-15)/3+8}) |- (14,8) -- (9,8) -- cycle;

%% inverse clip the circle
\draw [fill=Green,saveuse path={circle}{(7,4) circle (3)}] ;
\invclip [circle];

%% fill the outer parts. Make all colors same. I made them different just for demo
\path[fill=blue!20,domain=0:4]    plot(\x,{((\x-2)^3)/4+6}) -| (9,4);
\path[fill=green!20,domain=10:14]  plot(\x,{((\x-12)^3)/4+2})  -| (5,0);
\path[fill=pink,domain=9:14]   plot(\x,{(\x-9)*(\x-15)/3+8}) |- (9,4);
\path[fill=orange,domain=0:5]   plot(\x,{-(1/3)*(\x+1)*(\x-5)}) |- (0,4);

\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

동일한 색상:

여기에 이미지 설명을 입력하세요

관련 정보