Draw Double Torus using Tikz and pgfplots in LaTeX – An attempt
Hello, in this tutorial, we will learn how to draw or plot double torus in LaTeX using Tikz and pgfplots. A double torus is also known as gen 2 torus or genus 2 torus.
I have done a lot of work in LaTeX, but till now this is the hardest task that I ever did in LaTeX. It might look easier but it is not.
I first tried to draw a single torus and then somehow managed to draw a double torus. (Like two torus in a single frame, but that was not enough)
You can check my previous tutorial: Draw Torus with Tikz in LaTeX with Equation
Double torus in LaTeX
After trying a lot of attempts I came to this point.
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{colormaps}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm,
height=15cm,
view={45}{45},
hide axis,
samples=40,
samples y=40,
domain=0:360,
y domain=0:360,
z buffer=sort, % Improve 3D rendering
colormap/viridis, % Set the colormap
axis equal % Keep the proportions correct
]
% First torus (placed on the left)
\addplot3[
surf,
shader=flat,
opacity=0.8, % Add some transparency
mesh/rows=40, % Match the number of samples
mesh/cols=40 % Match the number of samples y
]
(
{(2 + cos(x)) * cos(y)},
{(2 + cos(x)) * sin(y)},
{sin(x)}
);
% Second torus, placed side by side (translated along the x-axis)
\addplot3[
surf,
shader=flat,
opacity=0.8, % Add some transparency
mesh/rows=40, % Match the number of samples
mesh/cols=40, % Match the number of samples y
domain=0:360,
y domain=0:360
]
(
{(2 + cos(x)) * cos(y) + 5}, % Shifted by +5 units along the x-axis
{(2 + cos(x)) * sin(y)},
{sin(x)}
);
\end{axis}
\end{tikzpicture}
\end{document}
Output:
But this is not what is our expectation right?
We need to change the position slightly and blend the intersection position. So in my next attempt I did this:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{colormaps}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=15cm, % Increase the width of the plot
height=15cm, % Increase the height of the plot
view={45}{45}, % Adjust the viewing angle for better visualization
hide axis, % Hide the axes
samples=40, % Number of samples in the x direction
samples y=40, % Number of samples in the y direction
domain=0:360,
y domain=0:360,
z buffer=sort, % Improve 3D rendering
colormap/viridis, % Set the colormap
axis equal % Keep the proportions correct
]
% First torus (placed on the left)
\addplot3[
surf,
shader=flat,
opacity=0.8, % Add some transparency to blend the intersection
mesh/rows=40, % Match the number of samples
mesh/cols=40 % Match the number of samples y
]
(
{(2 + cos(x)) * cos(y)},
{(2 + cos(x)) * sin(y)},
{sin(x)}
);
% Second torus, intersecting the first one
\addplot3[
surf,
shader=flat,
opacity=0.8, % Add some transparency to blend the intersection
mesh/rows=40, % Match the number of samples
mesh/cols=40, % Match the number of samples y
domain=0:360,
y domain=0:360
]
(
{(2 + cos(x)) * cos(y) + 4}, % Shifted by +4 units along the x-axis
{(2 + cos(x)) * sin(y)},
{sin(x)}
);
\end{axis}
\end{tikzpicture}
\end{document}
Output:
You just need to change the viewing angle and distance in between these torus to get your desired result.


Leave a Reply