Hi all,
I have created the skeleton of a 3D grapher (still learning how to convert over to an app). The program runs fine, except when creating a wireframe with large meshes. The program creates an n x n matrix to store the z-values (later to be used for a "trace" subroutine). If I try 35x35 then I run into an insufficient memory error. However, when I check the actual matrix, it is less than 10kB in size. How in the world is 32MB of RAM getting filled up with such a simple routine?
Below is the source code. Before running the program, make sure to create a function named FXY whose formula is 1/390*(X^3*Y-X*Y^3). You can accomplish this via [SHIFT][xt(theta)n] -- aka the Define app. The program assumes FXY is already created and will use it to generate Z-values.
a, b, and c are the rotation angles about the x, y, and z axes using the right hand rule (hold your right hand with your fingers pointing at you, and index finger pointing to the sky -- your thumb is y, your middle finger is x, and index finger is z
n is the grid size
Some starting values:
xmin:=-10; xmax:=10; ymin:=-10; ymax:=10;
n:=15; a:=0; b:=-10; c:=10; zoom:=10;
Edit: Hm.. the "store" symbol got translated over into ▶ a quick search and replace should do the trick if you are copying
export GRAPH3D(xmin,xmax,ymin,ymax,n,a,b,c,zoom)
beginlocal i,j,dx,dy,x0,y0;
local xeye,yeye,zeye;
local xl,xr,yl,yr;
xl:=-1.; xr:=1.; yl:=-1.; yr:=1.;dx:=(xmax-xmin)/n; dy:=(ymax-ymin)/n;
// eyepoint
xeye:=xmax+5; yeye:=0; zeye:=0;// rotation angles
a*π/180.▶A; b*π/180.▶B; c*π/180.▶C;expr("[[1.,0.,0.],[0.,COS(A),-SIN(A)],[0.,SIN(A),COS(A)]]▶M1");
expr("
[[COS(B),0.,-SIN(B)],[0.,1.,0.],[SIN(B),0.,COS(B)]]▶M2");expr("[[COS(C),-SIN(C),0.],[SIN(C),COS(C),0.],[0.,0.,1.]]▶M3");
for j from 0 to n do
for i from 0 to n doxmin+dx*i▶X;
ymin+dy*j▶Y;
FXY(X,Y)▶Z; Z▶M0(i+1,j+1);
(n+1)*j+i+1▶K;
expr("M1*M2*M3*[[X],[Y],[Z]]▶M4");
abs(xeye-M4(1,1))▶Z;
M4(2,1)/Z*zoom▶X; M4(3,1)/Z*zoom▶Y;
(X,Y)▶L1(K);if i then
re(L1(K-1))▶x0;
im(L1(K-1))▶y0;line(X,Y,x0,y0,RGB(i/n*255,0,j/n*255));
end;if j then
re(L1(K-n-1))▶x0;
im(L1(K-n-1))▶y0;
line(X,Y,x0,y0,RGB(i/n*255,0,j/n*255));
end;// if X<xl then X▶xl; end;
// if X>xr then X▶xr; end;
// if Y<yl then Y▶yl; end;
// if Y>yr then Y▶yr; end;end;
end;freeze;
end;
Thanks in advance for testing this out!
Han
Edited: 24 Sept 2013, 6:52 p.m.