# Drawing a 3D plot of a lower half of a torus

As the title suggests, I would like a 3D plot of a lower half of a hollow torus with small radius 1 and large radius 2. I found an image online that resembles what I am looking for. Could anyone find a simple way to recreate the above image, including the downward pointing blue arrow and labelled axes drawn on?

• You've tagged the post with tikz-3dplot, have you tried that package? You should include some code for us to build off of (even just drawing the axes), rather than just asking for us to do the whole thing. – Jānis Lazovskis Nov 19 '17 at 14:33
• I have no experience with the packages, or otherwise I would include a code. – wrb98 Nov 19 '17 at 15:03
• I could perhaps learn from other codes, but I don't understand how to get a half torus, i.e. all the examples I've seen so far are of a full torus, and I cannot seem to figure out how to limit the z range of the plot to z < 0. – wrb98 Nov 19 '17 at 15:08

I present an asymptote example because this yields the arguably nicer output. However, the parametrization of the half-torus can be used for other packages as well.

 \documentclass{article}
\usepackage[inline]{asymptote}
\begin{document}
\thispagestyle{empty}
\begin{asy}
size(200);
import graph3;

currentprojection=perspective(5,6,3);
real R=4;
real a=1;

triple fs(pair t) {
return ((R+a*Cos(t.y))*Cos(t.x),(R+a*Cos(t.y))*Sin(t.x),a*Sin(t.y));
};

surface s=surface(fs,(0,180),(360,360),8,8,Spline);
draw(s,surfacepen=material(green+opacity(0.6), emissivepen=0.2*white),render(compression=Low,merge=true));

xaxis3(Label("$x$",1),xmin=0,xmax=7,Arrow3);
yaxis3(Label("$y$",1),ymin=0,ymax=7,Arrow3);
zaxis3(Label("$z$",1),zmin=0,zmax=4,Arrow3);

draw((4/sqrt(2),4/sqrt(2),-1)--(4/sqrt(2),4/sqrt(2),-4),blue,Arrow3);
\end{asy}
\end{document}


Of course, one needs to run asy between two compilations. It is possible to draw similar picture with pgfplots.

\documentclass[svgnames]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
axis equal,
domain=0:360,
y domain=180:360,
ticks=none,
view={130}{-35}
]

color=green!50!black,fill opacity=0.5%,faceted color=blue,z buffer=sort
]({(4+cos(y))*cos(x)},{(4+cos(y))*sin(x)},{sin(y)-0.01});
\end{axis}
\end{tikzpicture}
\end{document} However, the outcome is, arguably, less appealing. Of course, with additional effort one may improve this. On the other hand, the nice thing about asymptote is that there this additional effort is not necessary.

• I was wondering, is this also possible in tikz 3d plot? – wrb98 Nov 19 '17 at 16:39
• @wrb98 It is certainly possible. I added an example to my answer. However, I feel that it is far less straightforward to achieve satisfying results with pgfplots, but this is of course just my personal taste. I am sure that a real pgfplots expert can improve the quality of the result. – user121799 Nov 19 '17 at 17:11
• Interesting. Is it possible to (in pgfplots ) draw the positive vertical axis over the surface? It is under (see the arrow tip). – Sigur Nov 19 '17 at 17:11
• @Sigur : I agree that it's odd. I tried to improve the outcome by shifting the half-torus by -0.01 in z-direction, with very limited success. But I am no pgfplots expert. I'm just a marmot. ;-) – user121799 Nov 19 '17 at 17:14
• For the asymptote version, I assume one has to use the usual three steps of first running latex on the file, then running asy on the generated .asy file, and finally run latex again. But on the initial latex command, I get an Undefined control sequence error:  l.13 \ASYalign (-174.145695,81.289005)(-0.500000,-0.500000){\hbox to 0pt{\inc.... – murray Nov 19 '17 at 21:17