Post Reply 
GRAPH 3D v2.425 (20-FEB-2017)
02-09-2014, 12:15 AM
Post: #53
RE: GRAPH 3D v2.2 (beta, now with trace)
I think im doing exactly as said,but i have a message "Error:Invalid object" when plot the graphic too.

this is what im pasting:
// Graph 3D v2.221 (16-DEC-2013)
// by Han Duong

g3D_setdefault();
g3D_getfunc();
g3D_getsettings();
g3D_getwin();
g3D_setgrid();
g3D_getangles();
g3D_rotmatrix();
g3D_compute();
g3D_project();
g3D_draw();
g3D_keys();
xmin3D,xmax3D;
ymin3D,ymax3D;
zmin3D,zmax3D;
grid3D,zoom3D;
rotx,roty,rotz,Rx,Ry,Rz,Rot;
xc,yc,zc;
Zvals,Points2D,Point,zColor,zClip;
redraw3D=1,recompute3D=1,init3D=0;
minD,fxy="";


//----------------------------
// START FUNCTION
//----------------------------
view "Edit Function",START()
begin

if init3D==0 then
g3D_setdefault();
end;
startview(0,1);

end;

//----------------------------
// RESET FUNCTION
//----------------------------
View "Reset Plot Settings",RESET()
begin
g3D_setdefault();
end;


//----------------------------
// Symb FUNCTION
//----------------------------
Symb()
begin
startview(0,1);
end;

//----------------------------
// SymbSetup FUNCTION
//----------------------------
SymbSetup()
begin
msgbox("Use X and Y as the input variables.")
end;

//----------------------------
// PlotSetup FUNCTION
//----------------------------
PlotSetup()
begin
if init3D==0 then
g3D_setdefault();
end;
g3D_getsettings();
end;

//----------------------------
// Plot FUNCTION
//----------------------------
Plot()
begin
if init3D==0 then
g3D_setdefault();
end;
g3D_draw();
end;

//----------------------------
// Numb FUNCTION
//----------------------------
Num()
begin
local z_Values;
if init3D==0 then
g3D_setdefault();
end;
g3D_compute();
z_Values:=Zvals .+ zc;
editmat(Zvals);
end;

//----------------------------
// NumSetup FUNCTION
//----------------------------
NumSetup()
begin
if init3D==0 then
g3D_setdefault();
end;
g3D_setgrid();
end;


//----------------------------
// g3D_setdefault
//----------------------------
g3D_setdefault()
begin
xmin3D:=-10; xmax3D:=10;
ymin3D:=-10; ymax3D:=10;
zmin3D:=-10; zmax3D:=10;
zoom3D:=10; grid3D:=15;
rotx:=105; roty:=0; rotz:=5;
xc:=0; yc:=0; zc:=0;
redraw3D:=1;
recompute3D:=1;
init3D:=1;
fxy:="";
g3D_getfunc();
end;

//----------------------------
// g3D_getfunc
//----------------------------
g3D_getfunc()
begin
local i, ftot=0, fnew, fsel;

for i from 0 to 9 do
if ISCHECK(i) then
fsel:=i; ftot:=ftot+1;
end;
end;

if ftot==0 then
msgbox("Please enter/select a function!");
startview(0,1);
kill;
end;

if ftot>1 then
msgbox("Please select only one function!");
startview(0,1);
kill;
end;

fnew:=expr("STRING(V"+fsel+")");
if fnew<>fxy then
fxy:=fnew;
recompute3D:=1;
end;
return(recompute3D);

end;

//----------------------------
// g3d_getsettings
//----------------------------
view "Plot Settings (all)",g3D_getsettings()
begin
if init3D==0 then
g3D_setdefault();
end;
g3D_getwin();
g3D_getangles();
end;


//----------------------------
// g3D_getwin
//----------------------------
view "Set Viewing Window",g3D_getwin()
begin

local xmin,xmax,ymin,ymax,zmin,zmax;
local zoom;

if init3D==0 then
g3D_setdefault();
end;

xmin:=xmin3D; xmax:=xmax3D;
ymin:=ymin3D; ymax:=ymax3D;
zmin:=zmin3D; zmax:=zmax3D;
zoom:=zoom3D;

if input(
{xmin,xmax,ymin,ymax,zmin,zmax,zoom},
"Graph 3D View Window",
{
"Xmin=", "Xmax=",
"Ymin=", "Ymax=",
"Zmin=", "Zmax=",
"Zoom factor="
},
{
"Enter the value of back side of the viewing box",
"Enter the value of front side of the viewing box",
"Enter the value of left side of the viewing box",
"Enter the value of right side of the viewing box",
"Enter the value of bottom side of the viewing box",
"Enter the value of top side of the viewing box",
"Enter the zoom factor (must be > 0)"
},
{xmin3D,xmax3D,ymin3D,ymax3D,zmin3D,zmax3D,zoom3D})
then

if xmin>=xmax then
msgbox("Warning: Invalid Xmin/Xmax! Setting Xmax:=Xmin+1");
xmax:=xmin+1;
end;

if ymin>=ymax then
msgbox("Warning: Invalid Ymin/Ymax! Setting Ymax:=Ymin+1");
ymax:=ymin+1;
end;

if zmin>=zmax then
msgbox("Warning: Invalid Zmin/Zmax! Setting Zmax:=Zmin+1");
zmax:=zmin+1;
end;

if zoom3D<1 then
msgbox("Warning: zoom must be > 0; reset to 10");
zoom:=10;
end;

if (xmin<>xmin3D) or (xmax<>xmax3D) or
(ymin<>ymin3D) or (ymax<>ymax3D) or
(zmin<>zmin3D) or (zmax<>zmax3D)
then
recompute3D:=1;
xmax3D:=xmax; xmin3D:=xmin;
ymax3D:=ymax; ymin3D:=ymin;
zmax3D:=zmax; zmin3D:=zmin;
xc:=(xmax3D+xmin3D)/2;
yc:=(ymax3D+ymin3D)/2;
zc:=(zmax3D+zmin3D)/2;
end;

zoom3D:=zoom;


end;


end;

//----------------------------
// g3D_setgrid
//----------------------------
view "Set Grid Size",g3D_setgrid()
begin
local grid;

if init3D==0 then
g3D_setdefault();
end;

grid:=grid3D;
if input(grid,"Graph 3D Grid Size","Grid Size=","Enter N for an NxN grid",grid3D) then
if grid<1 then
msgbox("Warning: grid size must be > 0; reset to 15");
grid:=15;
end;
end;

if grid<>grid3D then
recompute3D:=1;
end;

grid3D:=grid;
end;

//----------------------------
// g3D_getangles
//----------------------------
view "Set Rotation Angles",g3D_getangles()
begin
local rx,ry,rz;

if init3D==0 then
g3D_setdefault();
end;

rx:=rotx; ry:=roty; rz:=rotz;

if input({rx,ry,rz},
"Graph 3D Rotation Angles",
{ "X-angle=", "Y-angle=", "Z-angle=" },
{
"Enter the angle (deg) about the x-axis",
"Enter the angle (deg) about the y-axis",
"Enter the angel (deg) about the z-axis"
},
{rotx,roty,rotz})
then
if (rx<>rotx) or (ry<>roty) or (rz<>rotz) then
rotx:=rx; roty:=ry; rotz:=rz;
end;
end;
end;

//----------------------------
// g3D_rotmatrix
//----------------------------
g3D_rotmatrix()
begin

A:=rotx; B:=roty; C:=rotz;
if HAngle==0 then
A:=A*PI/180; B:=B*PI/180; C:=C*PI/180;
end;

Rx:=[[1.,0.,0.],[0.,COS(A),-SIN(A)],[0.,SIN(A),COS(A)]];
Ry:=[[COS(B),0.,-SIN(B)],[0.,1.,0.],[SIN(B),0.,COS(B)]];
Rz:=[[COS(C),-SIN(C),0.],[SIN(C),COS(C),0.],[0.,0.,1.]];
Rot:=Rx*Ry*Rz;
Rot(3,4):=minD;

end;

//----------------------------
// g3D_compute
//----------------------------
g3D_compute()
begin

local i,j,dx,dy,xm,ym,func;
local m,minZ,maxZ;

if g3D_getfunc() then

iferr func:=STRING(V0); then func:=""; end;
V0:=fxy;

if recompute3D then

zColor:=makemat(RGB((grid3D+1-J)/grid3D*255,0,(I-1)/grid3D*255),grid3D+1,grid3D+1);
dx:=(xmax3D-xmin3D)/grid3D;
dy:=(ymax3D-ymin3D)/grid3D;
xm:=xmin3D-dx; ym:=ymin3D-dy;
Points2D:=makemat((xm+dx*I-xc,ym+dy*J-yc),grid3D+1,grid3D+1);

// apps currently have terrible bug handling
iferr
Zvals:=makemat(V0(xm+dx*I,ym+dy*J)-zc,grid3D+1,grid3D+1);
then
recompute3D:=1;
msgbox("Error during evaluation of function!");
V0:=func;
kill;
end; // end error trap

recompute3D:=0;

// get longest distance from center to prevent inversion
minZ:=min(Zvals); maxZ:=max(Zvals);
minD:=10+(max(abs(minZ),abs(maxZ))^2+(xmax3D-xc)^2+(ymax3D-yc)^2)^(.5);

end; // if recompute3D

V0:=func;

end; // if g3D_getfunc

end;


//----------------------------
// g3D_project
//----------------------------
g3D_project()
begin
local clip;

g3D_rotmatrix();
dimgrob_p(G1, 320, 240);
clip:=triangle(G1);
triangle_p(G1, Points2D, zColor, Zvals, { "N", -160, -120, minD*zoom3D }, Rot, clip);
blit_p(G0,G1);
end;


//----------------------------
// g3D_draw
//----------------------------
g3D_draw()
begin

if init3D==0 then
g3D_setdefault();
end;

g3D_compute();
g3D_project();
g3D_keys();
freeze;

end;


//----------------------------
// g3D_draw
//----------------------------
g3D_keys()
begin
local key,mousein, dx, dy;

while 1 do
key:=wait(-1);
if TYPE(key)==6 then break; end;
if key==-1 then break; end;

repeat
case
if key==1 then roty:=(roty+5) MOD 360; end;
if key==3 then roty:=(roty-5) MOD 360; end;
if key==4 then kill; end;
if key==7 then rotz:=(rotz-5) MOD 360; end;
if key==8 then rotz:=(rotz+5) MOD 360; end;
if key==2 then rotx:=(rotx-5) MOD 360; end;
if key==12 then rotx:=(rotx+5) MOD 360; end;
if key==45 then zoom3D:=max(zoom3D/1.05,.01); end;
if key==50 then zoom3D:=zoom3D*1.05; end;
end;
g3D_project();
until NOT IsKeyDown(key);

end; // end while

end;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
GRAPH 3D v2.425 (20-FEB-2017) - Han - 12-15-2013, 01:20 AM
RE: GRAPH 3D v2.1 - Han - 12-16-2013, 07:24 PM
RE: GRAPH 3D v2.1 - Han - 12-16-2013, 09:48 PM
RE: GRAPH 3D v2.2 (beta) - Terje Vallestad - 12-21-2013, 08:11 AM
RE: GRAPH 3D v2.1 - John Colvin - 12-17-2013, 02:51 AM
RE: GRAPH 3D v2.1 - Han - 12-17-2013, 03:19 AM
RE: GRAPH 3D v2.2 (beta) - Han - 12-18-2013, 07:14 PM
RE: GRAPH 3D v2.2 (beta) - ArielPalazzesi - 12-19-2013, 10:55 AM
RE: GRAPH 3D v2.2 (beta) - LarsF - 12-19-2013, 08:03 PM
RE: GRAPH 3D v2.2 (beta) - John Colvin - 12-19-2013, 11:54 PM
RE: GRAPH 3D v2.2 (beta) - Han - 12-20-2013, 12:07 AM
RE: GRAPH 3D v2.2 (beta) - Harold A Climer - 12-25-2013, 11:06 PM
RE: GRAPH 3D v2.2 (beta) - Han - 12-30-2013, 05:46 AM
RE: GRAPH 3D v2.2 (beta) - Thomas_Sch - 12-31-2013, 09:53 AM
RE: GRAPH 3D v2.2 (beta) - ArielPalazzesi - 12-31-2013, 05:42 PM
RE: GRAPH 3D v2.2 (beta) - eried - 01-01-2014, 07:54 AM
RE: GRAPH 3D v2.2 (beta) - Han - 01-02-2014, 06:28 AM
RE: GRAPH 3D v2.2 (beta) - ArielPalazzesi - 01-02-2014, 10:31 AM
RE: GRAPH 3D v2.2 (beta, now with trace) - fefer92 - 02-09-2014 12:15 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Albedo - 08-03-2015, 04:31 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - tom234 - 05-20-2019, 11:54 AM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Han - 05-22-2019, 01:17 AM
RE: GRAPH 3D v2.42 Memory leak - slawek39 - 12-19-2014, 05:38 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - akmon - 12-25-2014, 09:06 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 12-24-2014, 04:31 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 01-25-2015, 03:50 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 02-05-2015, 08:35 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 02-05-2015, 10:48 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 09-29-2015, 03:13 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 09-30-2015, 12:53 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 09-30-2015, 04:35 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Dacobi - 10-21-2015, 10:51 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 11-06-2015, 12:45 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 11-03-2016, 06:15 PM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 11-05-2016, 12:45 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 11-05-2016, 02:02 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 12-04-2016, 04:06 AM
RE: GRAPH 3D v2.422 (21-DEC-2014) - Han - 01-20-2017, 07:09 PM
RE: GRAPH 3D v2.424 (20-JAN-2017) - Han - 02-17-2017, 09:56 PM
RE: GRAPH 3D v2.424 (20-JAN-2017) - Han - 02-20-2017, 04:14 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Lessa - 08-16-2017, 08:54 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Han - 03-06-2017, 03:51 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Han - 08-21-2017, 12:00 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Lessa - 08-22-2017, 11:57 AM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Han - 08-24-2017, 05:33 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - akmon - 02-03-2018, 11:48 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Han - 02-06-2018, 07:25 PM
RE: GRAPH 3D v2.425 (20-FEB-2017) - Arno K - 04-08-2018, 04:04 PM



User(s) browsing this thread: 7 Guest(s)