# Drawing a ring around a torus (doughnut) using TikZ

I was trying to draw a 2-torus (a doughnut) using TikZ, based on the answer to my previous question Moebius Strip using Tikz, and got the following The result is impressive! However, the vertical circle does not look as surrounding the torus.

Q:

How could I give the right perspective of 3D?

MWE

WARNING: main tex-memory of my computer has been enhanced to compite this code

\documentclass{report}
\usepackage{amsmath,units}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
hide axis,
view={60}{60}
]
point meta=x,
colormap/greenyellow,
samples=40,
samples y=40,
z buffer=sort,
domain=0:360,
y domain=0:360
] (
{(3.5 + 0.5*cos(y))*cos(x)},
{(3.5 + 0.5*cos(y))*sin(x)},
{0.5*sin(y)});
samples=40,
domain=0:360,
thick
] (
{(3.5 + 0.5*cos(80))*cos(x)},
{(3.5 + 0.5*cos(80))*sin(x)},
{0.5*sin(80)});
samples=40,
domain=0:360,
thick
] (
{3.5 + 0.5*cos(x)},
{0},
{0.5*sin(x)});

\end{axis}
\end{tikzpicture}

\end{document}

• I'm marking this question as duplicate, see: solution 1, solution 2. Alternatively using pst-solides3d: solution 3 Jun 24 '13 at 12:33
• @juliohm None of the post you pointed out are solutions to my problem! And I checked them previously to post mine. The closest answer uses something called sketch and it's not explained how to use the sketch command. The other use postscript... which are not usable for my purposes. However, I thank your concern.
– Dox
Jun 24 '13 at 12:43
• @juliohm: To vote for closing a question as a duplicate, you have to click the close link underneath the question (I think you might not have enough reputation to see it, though). However, I don't think this is a duplicate, since the answers to your first link don't show how to draw a circle around the torus (Dox has the torus part in his question, he was specifically asking about the circle), and the second link is concerned with a much more complicated drawing that requires a different approach.
– Jake
Jun 24 '13 at 12:43
• @juliohm: Ah, I see that you can flag to close instead of directly voting. Anyway, my above comment is my explanation why I disagreed with your close flag in the flag review.
– Jake
Jun 24 '13 at 13:05

You'll have to manually adjust the domain over which the circle is evaluated, so that it's only drawn on the visible side: \documentclass{report}
\usepackage{amsmath,units}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
hide axis,
view={60}{30},
axis equal image,
]
point meta=x,
colormap/greenyellow,
samples=40,
samples y=20,
z buffer=sort,
domain=0:360,
y domain=0:360
] (
{(3.5 + 0.5*cos(y))*cos(x)},
{(3.5 + 0.5*cos(y))*sin(x)},
{0.5*sin(y)});
samples=40,
samples y=1,
domain=0:360,
thick
] (
{(3.5 + 0.5*cos(80))*cos(x)},
{(3.5 + 0.5*cos(80))*sin(x)},
{0.5*sin(80)});
samples=10,
samples y=1,
domain=-65:130,
thick
] (
{3.5 + 0.5*cos(x)},
{0},
{0.5*sin(x)});

\end{axis}
\end{tikzpicture}

\end{document}

• Thank you @jake! Once more, you've saved the day! Cheers.
– Dox
Jun 24 '13 at 12:36