Using pgfplots, I plotted a torus, with a knot that lies on its surface:
\begin{tikzpicture}
\begin{axis}[axis equal image]
\addplot3[domain=0:360, y domain=0:360, samples=20, surf, z buffer=sort]
(
{(2 + cos(x))*cos(y)},
{(2 + cos(x))*sin(y)},
{sin(x)}
);
\addplot3[domain=0:360, samples=50]
(
{(2 + cos(2*x))*cos(3*x)},
{(2 + cos(2*x))*sin(3*x)},
{sin(2*x)}
);
\end{axis}
\end{tikzpicture}
However, it turns out that the knot is not shown properly, because parts of it that should be hidden by the surface, aren't. It should look something like this:
One of the first things I tried is putting in a z buffer=sort key for the knot's graph, however, this just screws up the curve. I guess the issue is that the torus and the knot have to somehow know about each other, for z buffer=sort to work, but there is no good way to do so.
Are there other approaches? I am open to trying non-pgfplots solutions.



pgfplots, but will require more work. – Jan 04 '19 at 03:54asymptoteis, but I am about to learn! – bzm3r Jan 04 '19 at 04:13