# Triangulating a torus in tikz

I have this code for a torus in tikz:

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) ellipse (1.6 and .9);
\begin{scope}[scale=.8]
\path[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0) (-.9,0)--(0,-.56)--(.9,0);
\draw[rounded corners=28pt] (-1.1,.1)--(0,-.6)--(1.1,.1);
\draw[rounded corners=24pt] (-.9,0)--(0,.6)--(.9,0);
\end{scope}
\end{tikzpicture}
\end{document}


I would like a simple way to triangulate this picture to illustrate how we triangulate topological spaces. Thanks in advance for any help.

• I guess it won't be easy in TikZ but if you are willing to use asymptote please have a look here. (I understand that this is not a trianglulation, but this may be a starting point.) – marmot Apr 24 '18 at 4:19
• This is an algorithmic problem which does not really have anything to do with TeX. If, however, you implement triangular tessellation in TeX, be sure to make it into a package and upload it to CTAN. That said, here is a related post on Stack Overflow stackoverflow.com/questions/1999397 – Henri Menke Apr 24 '18 at 10:52
• And note that this question has already been asked here. Yet, in contrast to the situation there, you do show an MWE, so I am not closing yours as a duplicate. – marmot Apr 24 '18 at 17:13
• @marmot I am actually looking to generate something like the image in your link, but no one has answered that question. Also, what is an MWE? – rosterherik Apr 25 '18 at 1:42
• @rosterherik MWE stands for minimal working example. Most questions (should) have one since this is the starting point of an answer. – marmot Apr 25 '18 at 4:06

Here is an admittedly poor attempt with pgfplots.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
view={30}{60},axis lines=none,
]
samples=10,
domain=0:2*pi,y domain=0:2*pi,
z buffer=sort]
({(2+cos(deg(x)))*cos(deg(y))},
{(2+cos(deg(x)))*sin(deg(y))},
{sin(deg(x))});
\pgfplotsinvokeforeach{0,...,8}{
({(2+cos(x))*cos(x+#1*40)},
{(2+cos(x))*sin(x+#1*40)},
{sin(x)});
}
\end{axis}
\end{tikzpicture}

\end{document}


It does show the triangles, but not paint the surfaces.

• Thank you for the effort! The first one is actually very close to what I'm looking for. Is it possible to use less triangles? My goal is to give an example of what a triangulation looks like to an audience who is unfamiliar with topology, and I think that if there are a lot of triangles the picture becomes loud and harder to interpret without spending a while looking at it. – rosterherik Apr 25 '18 at 1:38
• @rosterherik Sure. How many? The number of triangles is controlled by samples. Interestingly, if you set samples to 10, you get 9 times 9 faces. That's why \pgfplotsinvokeforeach{0,...,8}{ runs over 9 (and not 10) numbers. (I better do not tell you how long it took me to figure that out. ;-) – marmot Apr 25 '18 at 3:11
• I think this was helpful enough that I can play around on my own to get the look that I want. Thank you for the help! – rosterherik Apr 25 '18 at 3:45