# Question

I recently asked a question here: How to plot a lattice of points on the surface of a torus?

Where I have two answers, but both render incorrectly on my machine.

They are supposed to look like:

## Given Images  But they actually look like:

## Rendered Images  I've included the code at the end of this post.

## The Problem

It appears that the solid surfaces are not blocking the lines rendered later, as they should, but instead the arrows are being layered on top of the torus graphic. I've done a fair bit of goggling but can't seem to find an answer anywhere.

# Original Code

Credits to Alex \documentclass{standalone} \usepackage{asymptote}

\begin{document}

\begin{asy}[width=10cm,height=10cm]
import graph3;
import three;

size3(200);
currentprojection=orthographic(3,3,5);
currentlight=light(gray(0.4),specularfactor=3,viewport=true,
(-0.5,-0.25,0.45),(0.5,-0.5,0.5),(0.5,0.5,0.75));

int nb = 20, ns = 10;
real rb = 5.0, rs = 2.0;

triple torus(pair z) {

return ((rb + rs*cos(2*pi*z.x/ns))*cos(2*pi*z.y/nb),
(rb + rs*cos(2*pi*z.x/ns))*sin(2*pi*z.y/nb),
rs*sin(2*pi*z.x/ns));

}

surface site = scale3(0.1)*unitsphere;

for(int k1=0; k1<ns; ++k1) {
for(int k2=0; k2<nb; ++k2) {
draw(surface(torus((k1,k2))--torus((k1+1,k2))--torus((k1+1,k2+1))--torus((k1,k2+1))--cycle),
lightgray);
draw(torus((k1,k2))--torus((k1+1,k2)),Arrow3);
draw(torus((k1,k2))--torus((k1,k2+1)),Arrow3);
draw(shift(torus((k1,k2)))*site,red);
}
}

\end{asy}

\end{document}


Credits to g-kov

size(200);
import graph3;

pen surfPen=rgb(1,0.7,0);
pen xarcPen=deepblue+0.7bp;
pen yarcPen=deepred+0.7bp;

currentprojection=perspective(5,4,4);

real R=2;
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,0),(360,360),8,8,Spline);
draw(s,surfPen,render(compression=Low,merge=true));

int m=20;
int n=10;
real arcFactor=0.85;

pair p,q;

for(int i=1;i<=n;++i){
for(int j=0;j<m;++j){
p=(j*360/m,(i%n)*360/n);
q=(((j+arcFactor)%m)*360/m,i*360/n);
draw(fs(p)..fs((p+q)/2)..fs(q),xarcPen,Arrow3(size=4));
q=(j*360/m,((i%n)-arcFactor)*360/n);
draw(fs(p)..fs((p+q)/2)..fs(q),yarcPen,Arrow3(size=3));
dot(fs(p));
}
}


I have modified both scripts in the following way to make them render with the correct orientation: First Script:

... for(int k1=ns; k1>0; --k1) ...


Second Script:

No Modifications.


My problem was that the default version of asymptote shipped with texstudio (or in the ubuntu repos) doesn't have support for rendering.

When using the -render=4 flag, I got the warning:

runtime: to support onscreen rendering, please install glut library, run ./configure, and recompile


The solution to this was to install the following:

sudo apt-get install freeglut3-dev libz-dev libosmesa-dev libfftw3-dev libfftw3-doc texi2dvi


And the compiling from source via:

./configure
make
make install


After configure you will also be asked to

wget http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.2d.tar.gz


Which you should do before rerunning ./configure and continuing.

Running asymptote as: /usr/bin/asy -f pdf -noprc -render=-1 torus-latice.asy then worked without a hitch.