help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Using Plotmtv with Octave

 From: Ted Harding Subject: Using Plotmtv with Octave Date: Tue, 18 Apr 1995 00:14:01 +0200 (BST)

```Hi All,

Another instalment. Here is a skeleton m-file (mtv_surf.m) to draw surfaces
from octave using the plotting package Plotmtv.

Two example files are also appended for testing: spere.m (draws a simple
sphere) and kuen.m (draws the rather interesting Kuen surface - formulae
cribbed from Maple). The delay while the data are written to file is
(naturally, since fpdintf is used for the ASCII writing) longish,
especially for the latter example. However, re-draw is quite quick
once the plot is up.

Various extensions and embellishments are possible using the Plotmtv
resources. In particular, cells can be given a different colours
depending on, perhaps, the values of (u,v) or (x,y,z), or (most simply)
passed to the function as a matrix "colours" conformal with X,Y,Z.

Best wishes to all,
Ted.                                     (address@hidden)

------------------------------ mtv_surf.m ----------------------------------
function mtv_surf(X,Y,Z)
# usage: mtv_surf(X,Y,Z)
#
# displays a surface from parametrised coordinates X,Y,Z.
#
# It is assumed that X and Y and Z have been generated from "mesh"
# matrices U, V of parameters (u,v) as in:
#
# u = urange; v = vrange; [U,V] = meshdom(u,v);
# X = f(U,V); Y = g(U,V); Z = h(U,V);
#
file = "/tmp/mtv_curves_dat"
fopen(file,"a");
fprintf(file,"\n\$ data=curve3d\n");
fprintf(file,"%% hiddenline=True\n\n");
[m,n]=size(X);
for i=1:m-1
for j=1:n-1
fprintf(file,"%g %g %g\n",X(i,j),Y(i,j),Z(i,j));
fprintf(file,"%g %g %g\n",X(i+1,j),Y(i+1,j),Z(i+1,j));
fprintf(file,"%g %g %g\n",X(i+1,j+1),Y(i+1,j+1),Z(i+1,j+1));
fprintf(file,"%g %g %g\n\n",X(i,j+1),Y(i,j+1),Z(i,j+1));
endfor
endfor
fclose(file)

mtv_cmd = sprintf("plotmtv -3d %s",file);
system(mtv_cmd);
============================================================================

------------------------------ sphere.m ------------------------------------
u=2*pi*0.025*(0:40)'; v=pi*0.05*(0:20); [U,V]=meshdom(u,v);
X=cos(U).*sin(V); Y=sin(U).*sin(V); Z=cos(V);
mtv_surf(X,Y,Z);
============================================================================

------------------------------ kuen.m --------------------------------------
u=4*0.05*(-20:20)'; v=pi*0.05*(1:19)'; [U,V]=meshdom(u,v);
D = 1 + U.*U.*sin(V).*sin(V);
X = 2*(cos(U)+U.*sin(V)).*sin(V)./D;
Y = 2*(sin(U)-U.*cos(V)).*sin(V)./D;
Z = log(tan(0.5*V)) + 2*cos(V)./D;
mtv_surf(X,Y,Z);
============================================================================
```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]
• Using Plotmtv with Octave, Ted Harding <=