This is the diagram I would like to recreate. (from https://en.wikipedia.org/wiki/Hyperbolic_triangle)

enter image description here

From Is there any easy way to draw a ruled surface like a hyperbolic paraboloid in TikZ?, I found a way to draw the saddle-shaped surface.

enter image description here

Is there a way to draw the triangle on it? And get the colours/transparency like the picture?

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3 [surf,shader=flat,draw=black] {x^2-y^2};
\end{axis}
\end{tikzpicture}
\end{document} 
  • Welcome to TeX.SX! It seems that you are asking for a mathematical function for the hyperbolic triangle. If this is the case then this is the wrong page to ask that kind of question. If you would have such a function you should already have an idea of how to draw it. We could then help to fine-tune the plots so they differ from each other. – Stefan Pinnow Aug 16 at 17:57
  • Welcome, you might want to have a look at tex.stackexchange.com/questions/108915/… – BambOo Aug 16 at 17:59
up vote 8 down vote accepted

In principle it is very simple: draw a parametric curve on the manifold and fill it.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\tikzset{declare function={%
fx(\x)=ifthenelse(\x<0,0.75*(\x+1),0.75*(-\x+1));
fy(\y)=ifthenelse(\y<0,0,ifthenelse(\y>1,-2+\y,-\y));
}}
\begin{tikzpicture}
\begin{axis}[view={-20}{45},axis lines=none,colormap/cool]
\addplot3 [surf,shader=interp,draw=black,domain=-1.2:1.2,domain y=-1.5:1.5,opacity=0.6] {x^2-y^2};
\addplot3 [domain=-2:2,samples=81,smooth,fill=green,fill opacity=0.1] ({fx(x)},{fy(x)},{fx(x)^2-fy(x)^2});
\end{axis}
\end{tikzpicture}
\end{document} 
\begin{tikzpicture}
\begin{axis}[samples=41]
\addplot[domain=-2:2] {fx(x)};
\addplot[blue,domain=-2:2] {fy(x)};
\end{axis}
\end{tikzpicture}

enter image description here

UPDATE: Tried to accommodate the requests in your comment. Please note also that the boundaries of the triangle are not pixelated on the pdf, the pixelation comes from the conversion to png.

ADDENDUM: Transparent plot with tikz-3dplot. Note, however, that the top contour is guessed. You can not easily adjust the view angles here without doing some math before.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{shadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\tikzset{declare function={%
f(\x,\y)=\x*\x-\y*\y;
fx(\x)=ifthenelse(\x<0,0.75*(\x+1),0.75*(-\x+1));
fy(\y)=ifthenelse(\y<0,0,ifthenelse(\y>1,-2+\y,-\y));
}}
\usetikzlibrary{backgrounds,calc,positioning}
\begin{document}
\pgfmathsetmacro{\xmax}{1}
\pgfmathsetmacro{\ymax}{1.5}
\foreach \X in {190}
{\tdplotsetmaincoords{130}{\X} 
\begin{tikzpicture}[font=\sffamily,xscale=4,yscale=2]
%\node at (0,0) {\X};
\begin{scope}[tdplot_main_coords,samples=61,smooth,variable=\x]
 \draw[name path=boundary] plot[domain=-\ymax:\ymax] (-\xmax,{\x},{f(-\xmax,\x)})
 -- plot[domain=-\xmax:\xmax] (\x,{\ymax},{f(\x,\ymax})
 -- plot[domain=\ymax:-\ymax] (\xmax,{\x},{f(\xmax,\x)})
 -- plot[domain=\xmax:-\xmax] (\x,{-\ymax},{f(\x,-\ymax)});
 \tikzset{declare function={ytop(\x)=0.35-0.2*(\x/\xmax);}}
 \draw[name path=top] plot[domain=-\xmax:\xmax]  ({\x},{ytop(\x)},{f(\x,ytop(\x))});
 \shade [%draw,blue,ultra thick,
   top color=blue!80,bottom color=blue,opacity=0.3,
    name path=back,
    intersection segments={
    of=top and boundary,
    sequence={B2--A2[reverse]}
  }];
 \shade [%draw,blue,ultra thick,
    top color=blue!80,bottom color=blue,opacity=0.3,
    name path=front,
    intersection segments={
    of=top and boundary,
    sequence={B3--B0--A1--A2} 
}];
 \shadedraw[thick,top color=green!20,bottom color=green!40,opacity=0.6] 
 plot[variable=\x,domain=-2:2,samples=81] ({fx(\x)},{fy(\x)},{fx(\x)^2-fy(\x)^2});
\end{scope}
\end{tikzpicture}}
\end{document}

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.