--------------------------------------------------------------- --------- Surface Plot --------- --------- A perverse use of MathPad --------- --------------------------------------------------------------- -- by "Michael W. Martin" include "vector_defs" -- some functions for mapping mod(m,n) = m - trunc(m/n)*n snake(i, k, min, max, ds) = min + ds*mod(i-1,k) when mod(trunc((i-1)/k),2) = 0, max - ds*mod(i-1,k) otherwise line(i, k, min, ds) = min + ds*trunc((i-1)/k) -- data to control the granularity and range xs = 14; ys = 14; n = xs*ys xmin := -pi:; xmax := pi:; dx := (xmax - xmin)/(xs-1): ymin := -pi:; ymax := pi:; dy := (ymax - ymin)/(ys-1): -- our functions x(i) = snake(i, xs, xmin, xmax, dx) when i <= n, line (i-n, xs, xmin, dx) otherwise y(i) = line (i, ys, ymin, dy) when i <= n, snake(i, ys, ymax, ymin, -dy) otherwise -- the surface fxy(xa,ya) = sin(xa)*cos(ya)+1/(1 + xa^2 + ya^2) -- the view angle M := MxM(Yaw(0*pi/180), MxM(Pitch(30*pi/180), Roll(45*pi/180))): -- the perspective length d := 20: -- define the x, y, z surface surf[i] = {x(i), y(i), fxy(x(i), y(i))} dim[2*n] -- map it to the view angle data[i] = MxV(M, surf[i]) dim[count(surf)] -- and add a little perspective data3[i] = {data[i,1], data[i,2]}*d/(d-data[i,3]) dim[2*n] -- and viol‡! plotline data3 Xmin=-4; Xmax=4 Ymin=-4; Ymax=4