Estou tentando preencher uma região complexa definida por seis interseções de 4 hipérboles. Como você pode ver aqui:
Em particular quero preencher a região que é delimitada e definida pelos 6 pontos. Eu sei as coordenadas exatas dos p_i
's e as equações exatas de cada hipérbole. Como posso concatená-los e preencher a região?
Para completar, aqui está o código que tenho até agora:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\bndmax{5}
\def\bndmin{0.2}
\def\xS{1.5}
\def\gR{1.618034} % The golden ratio
\begin{tikzpicture}
\draw (-3,-3) grid (3,3);
\tikzset{func/.style={thick,color=orange!90}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\begin{scope}[shift={(\xS,1/\xS)}]
\tikzset{func/.style={thick,color=orange!60,dashed}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\end{scope}
\fill (\xS,1/\xS) circle (2pt);
\pgfmathsetmacro\x{-\gR*\xS}
\pgfmathsetmacro\y{1/(\gR*\xS)}
\coordinate (p1) at (\x,\y);
\pgfmathsetmacro\x{-(1/\gR)*\xS}
\pgfmathsetmacro\y{\gR*(1/\xS)}
\coordinate (p2) at (\x,\y);
\pgfmathsetmacro\x{1/(\gR*\gR)*\xS}
\pgfmathsetmacro\y{\gR*\gR/\xS)}
\coordinate (p3) at (\x,\y);
\pgfmathsetmacro\x{(1/\gR)*\xS}
\pgfmathsetmacro\y{-\gR*(1/\xS)}
\coordinate (p4) at (\x,\y);
\pgfmathsetmacro\x{\gR*\xS}
\pgfmathsetmacro\y{-1/(\gR*\xS)}
\coordinate (p5) at (\x,\y);
\pgfmathsetmacro\x{\gR*\gR*\xS}
\pgfmathsetmacro\y{1/(\gR*\gR*\xS)}
\coordinate (p6) at (\x,\y);
\foreach \i in {1,2,3,4,5,6}
\fill[red] (p\i) circle (2pt) node[right]{$p_{\i}$};
\end{tikzpicture}
\end{document}
Responder1
Aqui está uma solução não totalmente automática. Não funciona se eu usar \xs
na definição da função in plot
, então tive que colocar isso manualmente (e portanto, estaticamente). Para os respectivos domínios, renomeei suas macros de ajuda reutilizadas para \x
e para e até e , para que possam ser usadas posteriormente. Então é só concatenar muitos comandos . Isso é importante, caso contrário, cada parcela individual será fechada, resultando em um estranho formato de diamante.\y
\xa
\ya
\xa
\xf
plot
--
--
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\bndmax{5}
\def\bndmin{0.2}
\def\xS{1.5}
\def\gR{1.618034} % The golden ratio
\begin{tikzpicture}
\draw (-3,-3) grid (3,3);
\tikzset{func/.style={thick,color=orange!90}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\begin{scope}[shift={(\xS,1/\xS)}]
\tikzset{func/.style={thick,color=orange!60,dashed}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\end{scope}
\fill (\xS,1/\xS) circle (2pt);
\pgfmathsetmacro\xa{-\gR*\xS}
\pgfmathsetmacro\ya{1/(\gR*\xS)}
\coordinate (p1) at (\xa,\ya);
\pgfmathsetmacro\xb{-(1/\gR)*\xS}
\pgfmathsetmacro\yb{\gR*(1/\xS)}
\coordinate (p2) at (\xb,\yb);
\pgfmathsetmacro\xc{1/(\gR*\gR)*\xS}
\pgfmathsetmacro\yc{\gR*\gR/\xS)}
\coordinate (p3) at (\xc,\yc);
\pgfmathsetmacro\xd{(1/\gR)*\xS}
\pgfmathsetmacro\yd{-\gR*(1/\xS)}
\coordinate (p4) at (\xd,\yd);
\pgfmathsetmacro\xe{\gR*\xS}
\pgfmathsetmacro\ye{-1/(\gR*\xS)}
\coordinate (p5) at (\xe,\ye);
\pgfmathsetmacro\xf{\gR*\gR*\xS}
\pgfmathsetmacro\yf{1/(\gR*\gR*\xS)}
\coordinate (p6) at (\xf,\yf);
\foreach \i in {1,2,3,4,5,6}
\fill[red] (p\i) circle (2pt) node[right]{$p_{\i}$};
\clip (p1) plot[domain=\xa:\xb] (\x,{-1/\x}) -- plot[domain=\xb:\xc] (\x,{-1/(\x-1.5)+1/1.5}) -- plot[domain=\xc:\xf] (\x,{1/\x}) -- plot[domain=\xf:\xe] (\x,{-1/(\x-1.5)+1/1.5}) -- plot[domain=\xe:\xd] (\x,{-1/\x}) -- plot[domain=\xd:\xa] (\x,{1/(\x-1.5)+1/1.5}) --cycle;
\fill[opacity=0.3,blue!30!cyan] (\xa,\yd) rectangle (\xf,\yc);
\end{tikzpicture}
\end{document}
Editar 1:Apenas algumas pequenas melhorias:
- expandiu a grade para 10x10
- melhorou o recorte geral
- fixou os limites de modo que todas as funções sejam desenhadas em todo o domínio
- coloque o preenchimento azul em uma camada de fundo, para que não se sobreponha espacialmente às funções ou pontos
.
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\pgfdeclarelayer{background layer}
\pgfsetlayers{background layer,main}
\begin{document}
\def\bndmax{6.5}
\def\bndmin{0.15}
\def\xS{1.5}
\def\gR{1.618034} % The golden ratio
\begin{tikzpicture}
\clip (-5cm-0.2pt,-5cm-0.2pt) rectangle (5cm+0.pt,5cm+0.2pt);
\draw (-5,-5) grid (5,5);
\draw[thick] (-5,0) -- (5,0);
\draw[thick] (0,-5) -- (0,5);
\tikzset{func/.style={thick,color=orange!90}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\begin{scope}[shift={(\xS,1/\xS)}]
\tikzset{func/.style={thick,color=orange!60,dashed}}
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{-1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (\x,{1/\x});
\draw[func,domain=-\bndmax:-\bndmin] plot [samples=200] (-\x,{-1/\x});
\end{scope}
\fill (\xS,1/\xS) circle (2pt);
\pgfmathsetmacro\xa{-\gR*\xS}
\pgfmathsetmacro\ya{1/(\gR*\xS)}
\coordinate (p1) at (\xa,\ya);
\pgfmathsetmacro\xb{-(1/\gR)*\xS}
\pgfmathsetmacro\yb{\gR*(1/\xS)}
\coordinate (p2) at (\xb,\yb);
\pgfmathsetmacro\xc{1/(\gR*\gR)*\xS}
\pgfmathsetmacro\yc{\gR*\gR/\xS)}
\coordinate (p3) at (\xc,\yc);
\pgfmathsetmacro\xd{(1/\gR)*\xS}
\pgfmathsetmacro\yd{-\gR*(1/\xS)}
\coordinate (p4) at (\xd,\yd);
\pgfmathsetmacro\xe{\gR*\xS}
\pgfmathsetmacro\ye{-1/(\gR*\xS)}
\coordinate (p5) at (\xe,\ye);
\pgfmathsetmacro\xf{\gR*\gR*\xS}
\pgfmathsetmacro\yf{1/(\gR*\gR*\xS)}
\coordinate (p6) at (\xf,\yf);
\foreach \i in {1,2,3,4,5,6}
\fill[red] (p\i) circle (2pt) node[right]{$p_{\i}$};
\begin{pgfonlayer}{background layer}
\clip (p1) plot[domain=\xa:\xb] (\x,{-1/\x}) -- plot[domain=\xb:\xc] (\x,{-1/(\x-1.5)+1/1.5}) -- plot[domain=\xc:\xf] (\x,{1/\x}) -- plot[domain=\xf:\xe] (\x,{-1/(\x-1.5)+1/1.5}) -- plot[domain=\xe:\xd] (\x,{-1/\x}) -- plot[domain=\xd:\xa] (\x,{1/(\x-1.5)+1/1.5}) --cycle;
\fill[opacity=0.3,blue!30!cyan] (\xa,\yd) rectangle (\xf,\yc);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
Responder2
Embora você tenha as coordenadas de cada vértice da sua região complexa, você pode desenhá-lo com um único caminho:
\documentclass{standalone}
\usepackage{tikz}
\def\xS{1.5}
\def\gR{1.618034} % The golden ratio
\begin{document}
\begin{tikzpicture}
\draw[samples=30,line join=round,fill=lime]
plot [domain=-\gR*\xS:-(1/\gR)*\xS] (\x,-{1/\x})
-- plot [domain=-\gR*\xS:-(1/\gR)*\xS] (\x+\xS,{-(1/\x)+(1/\xS)})
-- plot [domain=1/(\gR*\gR)*\xS:\gR*\gR*\xS] (\x,{1/\x})
-- plot [domain=\gR*\xS:{(1/\gR)*\xS}] (\x+\xS,{-1/\x+1/\xS})
-- plot [domain=\gR*\xS:{(1/\gR)*\xS}] (\x,{-1/\x})
-- plot [domain=-1/(\gR*\gR)*\xS:-\gR*\gR*\xS] (\x+\xS,{1/\x+1/\xS})
-- cycle;
\end{tikzpicture}
\end{document}
Você pode até variar o parâmetro `\xS':
\begin{tikzpicture}
\foreach \gray in {10,20,...,90}{
\pgfmathsetmacro{\xS}{.5+\gray/100*1.5}
\draw[samples=30,line join=round,draw=black!\gray!yellow]
plot [domain=-\gR*\xS:-(1/\gR)*\xS] (\x,-{1/\x})
-- plot [domain=-\gR*\xS:-(1/\gR)*\xS] (\x+\xS,{-(1/\x)+(1/\xS)})
-- plot [domain=1/(\gR*\gR)*\xS:\gR*\gR*\xS] (\x,{1/\x})
-- plot [domain=\gR*\xS:{(1/\gR)*\xS}] (\x+\xS,{-1/\x+1/\xS})
-- plot [domain=\gR*\xS:{(1/\gR)*\xS}] (\x,{-1/\x})
-- plot [domain=-1/(\gR*\gR)*\xS:-\gR*\gR*\xS] (\x+\xS,{1/\x+1/\xS})
-- cycle;
}
\end{tikzpicture}
Mas se você não conhece as coordenadas, sempre há uma solução usando dois caminhos de clipe com gráficos encadeados (funciona se \bndmax
e \bndmin
forem escolhidos corretamente):
\documentclass{standalone}
\usepackage{tikz}
\def\bndmax{5}
\def\bndmin{0.2}
\def\xS{1.5}
\def\gR{1.618034} % The golden ratio
\begin{document}
\begin{tikzpicture}
\draw (-\bndmax,-1/\bndmin) grid (\bndmax,1/\bndmin);
\path[clip] plot [samples=200,domain=-\bndmax:-\bndmin] (-\x,{1/\x})
-- plot [samples=200,domain=-\bndmin:-\bndmax] (\x,{1/\x})
-- plot [samples=200,domain=-\bndmax:-\bndmin] (\x,{-1/\x})
-- plot [samples=200,domain=-\bndmin:-\bndmax] (-\x,{-1/\x})
-- cycle;
\fill[green,fill opacity=.3]
(-\bndmax,-1/\bndmin) rectangle (\bndmax,1/\bndmin);
\begin{scope}[shift={(\xS,1/\xS)}]
\path[clip] plot [samples=200,domain=-\bndmax:-\bndmin] (-\x,{1/\x})
-- plot [samples=200,domain=-\bndmin:-\bndmax] (\x,{1/\x})
-- plot [samples=200,domain=-\bndmax:-\bndmin] (\x,{-1/\x})
-- plot [samples=200,domain=-\bndmin:-\bndmax] (-\x,{-1/\x})
-- cycle;
\fill[red,fill opacity=.7]
(-\bndmax,-1/\bndmin) rectangle (\bndmax,1/\bndmin);
\end{scope}
\end{tikzpicture}
\end{document}
Responder3
Você pode usar PGFPlots para isso.
Eu defini duas funções,
declare function={f(\x)=min(1/\x,-1/\x);},
declare function={g(\x)=max(1/\x,-1/\x);}
que correspondem às partes negativas (positivas) das hipérboles, e então as utilizou para definir duas novas funções
declare function={h(\x)=max(f(x),f(x-1.5)+1/1.5);},
declare function={i(\x)=min(g(x),g(x-1.5)+1/1.5);}
que correspondem à maior (inferior) das partes positivas (negativas) não deslocadas e deslocadas.
Eles podem então ser usados em um gráfico empilhado para colorir a área. Para garantir que apenas as partes entre o seu p1
e p6
sejam coloridas, podemos aproveitar o fato de que as coordenadas indefinidas são descartadas automaticamente, então adiciono o termo
*1/(h(x)<i(x))
o que leva a uma divisão por zero fora da nossa região de interesse, então o gráfico começa e termina onde queremos.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
declare function={f(\x)=min(1/\x,-1/\x);},
declare function={g(\x)=max(1/\x,-1/\x);},
declare function={h(\x)=max(f(x),f(x-1.5)+1/1.5);},
declare function={i(\x)=min(g(x),g(x-1.5)+1/1.5);}
]
\begin{axis}[
domain=-5:5,
ymin=-5,ymax=5,
samples=101,
no markers,
smooth
]
\addplot [draw=none, stack plots=y] {h(x)*1/(h(x)<i(x))};
\addplot [draw=none, fill=yellow, thick, stack plots=y] {i(x)*1/(h(x)<i(x))- h(x)*1/(h(x)<i(x))}\closedcycle;
\addplot [black] {f(x)};
\addplot [black] {g(x)};
\addplot [black, dashed] {f(x-1.5)+1/1.5};
\addplot [black, dashed] {g(x-1.5)+1/1.5};
\end{axis}
\end{tikzpicture}
\end{document}
Responder4
Para quem procura o equivalente ao PSTricks.
\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pst-eucl,pst-plot}
\def\f(#1){1 #1 div}
\def\F(#1){\f(#1 1.5 sub) 1 1.5 div add}
\def\g(#1){\f(#1 neg)}
\def\G(#1){\g(#1 1.5 sub) 1 1.5 div add}
\def\x(#1){\psGetNodeCenter{#1}#1.x}
\psset{yMaxValue=4,yMinValue=-4,plotpoints=6001}
\begin{document}
\begin{pspicture}[showgrid=false](-4.25,-4.25)(5.5,4.5)
\psclip{\psframe[linestyle=none,linewidth=0pt](-4,-4)(5,4)}
\pstInterFF[PosAngle=135]{\g(x)}{\F(x)}{-2}{P_1}
\pstInterFF[PosAngle=135]{\g(x)}{\G(x)}{-1}{P_2}
\pstInterFF[PosAngle=180]{\G(x)}{\f(x)}{1}{P_3}
\pstInterFF[PosAngle=90]{\G(x)}{\f(x)}{3}{P_4}
\pstInterFF[PosAngle=-45]{\G(x)}{\g(x)}{2}{P_5}
\pstInterFF[PosAngle=0]{\g(x)}{\F(x)}{1}{P_6}
\pscustom*[linecolor=yellow]
{
\psplot{\x(P_1)}{\x(P_2)}{\g(x)}
\psplot{\x(P_2)}{\x(P_3)}{\G(x)}
\psplot{\x(P_3)}{\x(P_4)}{\f(x)}
\psplot{\x(P_4)}{\x(P_5)}{\G(x)}
\psplot{\x(P_5)}{\x(P_6)}{\g(x)}
\psplot{\x(P_6)}{\x(P_1)}{\F(x)}
}
\psplot[linecolor=red]{-4}{5}{\f(x)}
\psplot[linecolor=blue]{-4}{5}{\g(x)}
\psset{linestyle=dashed,dash=3pt 1pt}
\psplot[linecolor=red]{-4}{5}{\F(x)}
\psplot[linecolor=blue]{-4}{5}{\G(x)}
\endpsclip
\psaxes[labelFontSize=\scriptscriptstyle,linecolor=gray]{->}(0,0)(-4,-4)(5,4)[$x$,0][$y$,90]
\end{pspicture}
\end{document}
Notas
\psset{saveNodeCoors}
\def\x(#1){N-#1.x}
pode ser usado para substituir
\def\x(#1){\psGetNodeCenter{#1}#1.x}
Última atualização
Com notação infixa por conveniência.
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl,pst-plot}
\def\f(#1){(1/(#1))}
\def\F(#1){(\f(#1-1.5)+1/1.5)}
\def\g(#1){(\f(-(#1)))}
\def\G(#1){(\g(#1-1.5)+1/1.5)}
\def\x(#1){N-#1.x}
\pstVerb{/I2P {exec AlgParser cvx exec} def}
\begin{document}
\begin{pspicture}[showgrid=false,saveNodeCoors,algebraic,yMaxValue=4,yMinValue=-4,plotpoints=6001](-4.25,-4.25)(5.5,4.5)
\psclip{\psframe[linestyle=none,linewidth=0pt](-4,-4)(5,4)}
\pstInterFF[PosAngle=135]{{\g(x)} I2P}{{\F(x)} I2P}{-2}{P_1}
\pstInterFF[PosAngle=135]{{\g(x)} I2P}{{\G(x)} I2P}{-1}{P_2}
\pstInterFF[PosAngle=180]{{\G(x)} I2P}{{\f(x)} I2P}{1}{P_3}
\pstInterFF[PosAngle=90]{{\G(x)} I2P}{{\f(x)} I2P}{3}{P_4}
\pstInterFF[PosAngle=-45]{{\G(x)} I2P}{{\g(x)} I2P}{2}{P_5}
\pstInterFF[PosAngle=0]{{\g(x)} I2P}{{\F(x)} I2P}{1}{P_6}
\pscustom*[linecolor=yellow]
{
\psplot{\x(P_1)}{\x(P_2)}{\g(x)}
\psplot{\x(P_2)}{\x(P_3)}{\G(x)}
\psplot{\x(P_3)}{\x(P_4)}{\f(x)}
\psplot{\x(P_4)}{\x(P_5)}{\G(x)}
\psplot{\x(P_5)}{\x(P_6)}{\g(x)}
\psplot{\x(P_6)}{\x(P_1)}{\F(x)}
}
\psplot[linecolor=red]{-4}{5}{\f(x)}
\psplot[linecolor=blue]{-4}{5}{\g(x)}
\psset{linestyle=dashed,dash=3pt 1pt}
\psplot[linecolor=red]{-4}{5}{\F(x)}
\psplot[linecolor=blue]{-4}{5}{\G(x)}
\endpsclip
\psaxes[labelFontSize=\scriptscriptstyle,linecolor=gray]{->}(0,0)(-4,-4)(5,4)[$x$,0][$y$,90]
\foreach \i in {1,...,6}{\qdisk(P_\i){2pt}}
\end{pspicture}
\end{document}