Estoy intentando llenar una región compleja que está definida por seis intersecciones de 4 hipérbolas. Como puedes ver aquí:
En particular, quiero llenar la región delimitada y definida por los 6 puntos. Conozco las coordenadas exactas de las p_i
's y las ecuaciones exactas de cada hipérbola. ¿Cómo puedo concatenarlos y llenar la región?
Para completar, aquí está el código que tengo hasta ahora:
\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}
Respuesta1
Aquí hay una solución no completamente automática. No funciona si lo uso \xs
en la definición de la función en plot
, así que tuve que poner esto manualmente (y por lo tanto, estáticamente). Para los respectivos dominios, cambié el nombre de las macros de ayuda reutilizadas \x
a \y
y hasta \xa
y para que puedan usarse más adelante. Entonces solo está concatenando muchos comandos y . Esto es importante; de lo contrario, cada trama individual se cierra, lo que da como resultado una extraña forma de diamante.\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}
Edición 1:Sólo algunas mejoras menores:
- expandió la cuadrícula a 10x10
- Mejoró el recorte general.
- Se fijaron los límites de modo que todas las funciones se dibujen en el dominio completo.
- coloque el relleno azul en una capa de fondo, para que no se superponga parcialmente las funciones o puntos
.
\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}
Respuesta2
Si bien tienes las coordenadas de cada vértice de tu región compleja, puedes dibujarla con un solo trazado:
\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}
Incluso puedes variar el 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}
Pero si no conoce las coordenadas, siempre hay una solución usando dos trazados de recorte con gráficos encadenados (funciona si \bndmax
y \bndmin
se eligen correctamente):
\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}
Respuesta3
Puedes usar PGFPlots para esto.
Definí dos funciones,
declare function={f(\x)=min(1/\x,-1/\x);},
declare function={g(\x)=max(1/\x,-1/\x);}
que corresponden a las partes negativas (positivas) de las hipérbolas, y luego las usé para definir dos nuevas funciones
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 corresponden a la mayor (inferior) de las partes positivas (negativas) no desplazadas y desplazadas.
Luego se pueden usar en un diagrama apilado para colorear el área. Para asegurarnos de que solo las partes entre tu p1
y p6
estén coloreadas, podemos aprovechar el hecho de que las coordenadas no definidas se descartan automáticamente, por lo que agrego el término
*1/(h(x)<i(x))
lo que lleva a una división por cero fuera de nuestra región de interés, por lo que la trama comienza y termina donde 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}
Respuesta4
Para aquellos que buscan el equivalente de 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}
se puede utilizar para sustituir
\def\x(#1){\psGetNodeCenter{#1}#1.x}
Última actualización
Con notación infija por conveniencia.
\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}