Programming and Graphics

(Kiana) #1

7.7 Three-dimensional interactive graph 237


float xrange = xmax-xmin;
float yrange = ymax-ymin;
float zrange = zmax-zmin;

float xmargin = 0.1*xrange;
float ymargin = 0.1*yrange;
float zmargin = 0.1*zrange;

ortho (xmin-0.50*xrange, xmax+0.50*xrange
,ymin-0.50*yrange, ymax+0.50*yrange
,zmin-0.50*zrange, zmax+0.50*zrange);

//--- Graphics:

color (bgc);
clear ();

lookat (vx,vy,vz,0.0,0.0,0.0,twist);
rotate (angx, ’x’);
rotate (angy, ’y’);
rotate (angz, ’z’);
scale (zoom,zoom,zoom);

/*--------------------
Draw axes and labels
--------------------*/

if(Iaxes==1)
{
color (axc);
move (xmin,ymin,zmin);
draw (xmax,ymin,zmin);
move (xmin,ymin,zmin);
draw (xmin,ymax,zmin);
move (xmin,ymin,zmin);
draw (xmin,ymin,zmax);

//--- Print axes labels:

font ("/tmp/hfonts/futura.l");

textsize(0.9*xmargin,0.9*ymargin);

float ticx = xrange/ntcx; // x tick distance
float ticy = yrange/ntcy; // y tick distance
float ticz = yrange/ntcy; // z tick distance

move (xmax+0.5*ticx, ymin-0.1*ymargin,zmin);
drawstr(labelx);
Free download pdf