In every Asymptote animation example that I found (see e.g. here or here), the viewpoint is constant during the animation. I would like to make one which consists in a rotating viewpoint, the drawn objects being constant.
The following code works, but as you can see the resulting gif
is unsteady. How can I avoid this?
size(10cm,10cm);
import graph3;
import grid3;
//import animation;
import animate;
settings.render=1;
animation A;
A.global=false;
real xmin=-2, xmax=2;
real ymin=-2, ymax=1.5;
real zmin=-2.5, zmax=2.5;
limits((xmin,ymin,zmin),(xmax,ymax,zmax));
unitsize(3cm,3cm,2cm);
viewportmargin=(2,2);
////// PLANES ///////
pen bg=gray(0.9)+opacity(0.2);
draw(surface((xmax,ymin,zmin)--(xmax,ymin,zmax)--(xmin,ymin,zmax)--(xmin,ymin,zmin)--cycle),bg);
draw(surface((xmin,ymax,zmin)--(xmin,ymax,zmax)--(xmin,ymin,zmax)--(xmin,ymin,zmin)--cycle),bg);
draw(surface((xmax,ymax,zmin)--(xmax,ymin,zmin)--(xmin,ymin,zmin)--(xmin,ymax,zmin)--cycle),bg);
xaxis3(Label("$x$",MidPoint,align=Y-Z),Bounds(Both,Min),InTicks(Step=1),p=black);
yaxis3(Label("$y$",MidPoint,align=X-Z),Bounds(Both,Min),InTicks(Step=.5),p=black);
zaxis3(Label("$z$",MidPoint,align=X-Y),Bounds(Both,Min),InTicks(Step=2),p=black);
for(real i;i<6.28;i=i+0.05) {
currentprojection=perspective(camera=(2*cos(i),2*sin(i),2.5));
A.add();
save();
}
A.movie(loops=3,delay=50);
Edit I followed Harish Kumar's suggestion and added a bounding box; it's better but still far from perfect.
Code (only the end changes):
for(real i;i<6.28;i=i+.1) {
currentprojection=perspective(camera=(2*cos(i),2*sin(i),2.5));
picture pic;
add(pic,bbox(20mm));
A.add(pic);
save();
}
bbox(5000mm);
orshipout(bbox(5000mm));
outside the loop in my first code, it has no effect (that's why I added it in the loop).