HP Forums
3D Grapher and Insufficient Memory - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: 3D Grapher and Insufficient Memory (/thread-251203.html)



3D Grapher and Insufficient Memory - Han - 09-24-2013

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)
begin

local 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 do

xmin+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&#9654;xl; end;
// if X>xr then X&#9654;xr; end;
// if Y<yl then Y&#9654;yl; end;
// if Y>yr then Y&#9654;yr; end;

end;
end;

freeze;
end;

Thanks in advance for testing this out!

Han


Edited: 24 Sept 2013, 6:52 p.m.


Re: 3D Grapher and Insufficient Memory - Han - 09-24-2013

Nevermind, I found the culrpit -- lists can only have at most 999 objects! =(

Edited: 24 Sept 2013, 7:00 p.m.


Re: 3D Grapher (no more Insufficient Memory) - Han - 09-24-2013

export GRAPH3D(xmin,xmax,ymin,ymax,n,a,b,c,zoom)
begin

local 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*&#960;/180.&#9654;A; b*&#960;/180.&#9654;B; c*&#960;/180.&#9654;C;

expr("[[1.,0.,0.],[0.,COS(A),-SIN(A)],[0.,SIN(A),COS(A)]]&#9654;M1");
expr("
[[COS(B),0.,-SIN(B)],[0.,1.,0.],[SIN(B),0.,COS(B)]]&#9654;M2");

expr("[[COS(C),-SIN(C),0.],[SIN(C),COS(C),0.],[0.,0.,1.]]&#9654;M3");

L1:={}; L2:={};

for j from 0 to n do
L2&#9654;L1;
for i from 0 to n do

xmin+dx*i&#9654;X;
ymin+dy*j&#9654;Y;
FXY(X,Y)&#9654;Z; Z&#9654;M0(i+1,j+1);

expr("M1*M2*M3*[[X],[Y],[Z]]&#9654;M4");
abs(xeye-M4(1,1))&#9654;Z;
M4(2,1)/Z*zoom&#9654;X; M4(3,1)/Z*zoom&#9654;Y;
(X,Y)&#9654;L2(i+1);


if i then
re(L2(i))&#9654;x0;
im(L2(i))&#9654;y0;

line(X,Y,x0,y0,RGB(i/n*255,0,j/n*255));
end;

if j then
re(L1(i+1))&#9654;x0;
im(L1(i+1))&#9654;y0;
line(X,Y,x0,y0,RGB(i/n*255,0,j/n*255));
end;

// if X<xl then X&#9654;xl; end;
// if X>xr then X&#9654;xr; end;
// if Y<yl then Y&#9654;yl; end;
// if Y>yr then Y&#9654;yr; end;

end;
end;

freeze;
end;

Define FXY to be 1/390*(X^3*Y-X*Y^3) and try:

xmin=ymin=-10; xmax=ymax=10; n=50 (for a 50x50 wireframe grid), a=0, b=-10, c=5, zoom=10


Re: 3D Grapher and Insufficient Memory - Tim Wessman - 09-24-2013

Yeah, sorry about that. Basically was a forgotten limit leftover from the 39gII...

TW


Re: 3D Grapher and Insufficient Memory - Han - 09-25-2013

Does this mean a future update will remove this limit?


Re: 3D Grapher and Insufficient Memory - Tim Wessman - 09-25-2013

Can't ever promise anything, but provided there is an update I would think likely that change would be in it.

This also is starting to show the "age" of Dave's forum software. Being not able to handle unicode could shortly prove to be very, very annoying with prime pastings. :-)

TW


Edited: 25 Sept 2013, 2:46 a.m.


Re: 3D Grapher and Insufficient Memory - cyrille de Brébisson - 09-25-2013

Hello,

In order to block people to do stupid things (and in most cases, creating lists with more than 999 elements or matrices with more than 512 elements happends when someone tries to either break things or because they messed up), there is a limit on the size of such objects...

1 things that you can do to bypass it:
- create a list of list (or a list of matrices)

cyrille


Re: 3D Grapher and Insufficient Memory - Gilles Carpentier - 09-25-2013

Hi Cyrille,

I strongly hope that this will be changed. This is for example a very annoying limitation with the DIMGROB command.


Re: 3D Grapher and Insufficient Memory - steindid - 09-25-2013

+1
Didier


Re: 3D Grapher and Insufficient Memory - Han - 09-26-2013

Quote:
Hello,

In order to block people to do stupid things (and in most cases, creating lists with more than 999 elements or matrices with more than 512 elements happends when someone tries to either break things or because they messed up), there is a limit on the size of such objects...

1 things that you can do to bypass it:
- create a list of list (or a list of matrices)

cyrille


This severely limits the ability of the calculator. One cannot evaluate sums having more than 1,000 terms using the summation symbol "sigma" due to this limitation.


Re: 3D Grapher and Insufficient Memory - Pier Aiello - 09-27-2013

I beg to differ. Expand the object until the memory is free it's a better choice (imo).