help-octave
[Top][All Lists]
Advanced

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

## RE: Contour Plots? Delaunay Triangulations?

 From: Ted Harding Subject: RE: Contour Plots? Delaunay Triangulations? Date: Thu, 10 Jun 1999 01:16:24 +0100 (BST)

```On 09-Jun-99 John Smith wrote:
> I will have some data collected at regular (r,theta) values on a
> polar grid. It might not be complete, or completely regular.
>
> I want to draw a contour map, preferably with layers of solid colours.
> Grudgingly, I have had to admit that this is possible in Matlab. Is
> there good Octave - or other free code - method?
>
> The Matlab approach involves building a Delaunay triangulation over the
> points, interpolating from the triangulation onto a regular
> xy grid, and finally contouring the regular grid.
>
> The Voronoi/Delaunay triangulation algorithms are good candidates
> for inclusion within Octave - I think suitable C coded raw algorithms
> exist. Has anyone built ".oct" implementations?
>
> And are there any good ideas for drawing the contours? Gnuplot is a bit
> limitted.

Agreed about gnuplot. I don't use a Delaunay method (though it would be
useful to have Delaunay triangulation available ... ). However, for nice
contour plots I use PlotMTV. The m-file I use for interfacing to this
is appended (it is self-contained). Note the blank slots where you can
edit in extra "furniture" later if you wish.

PlotMTV generally does a rather handsome job of plotting/contouring.
Its contouring and surface drawing are based on fairly unsophisticated
algorithms, triangulating a regular grid and then using a "painter's
algortithm" (filling in the triangles from far to near), but it's pretty
effective.

I'm not sure where PlotMTV can best be found these days. It should be
on a number of ftp sites, and can also be found tucked away in some Linux
distributions (e.g. SuSE). The source code usually compiles cleanly.

If you don't want to go the full Delaunay hog, give PlotMTV a try.
DO read the documentation -- it's worth it!

For your problem (data on a polar grid) you will have to convert first
to rectangular coordinates. Not sure about how this would most easily fit
into the PlotMTV scheme of things. Maybe use the "CONTCURVE" data format
(see the %% lines below).

Good luck,
Ted.
=======================================================================

function mtv_ctr (t, u, v, w)
# usage: mtv_ctr(Z), mtv_ctr(Z,V), mtv_ctr(x,y,Z)  or  mtv_ctr(x,y,Z,V)
#
# where Z is a n x m matrix of values of f(x,y), x along rows & y UP cols
# i.e. it is assumed that Z has been obtained by the equivalent of
#
# [X,Y]=meshdom(x,y); Z = f(X,Y);
#
# and V is either an integer number of contours (default = 10)
#          or a vector of contour-level values (max = 98)
#
# The dimensions of the Z-mesh should both be not greater than 99.
# This uses the Plotmtv CONTOUR data format (Data Format Manual Sect. 7)
#
# Additional Plotmtv command-line options can be set in the
#        octave string variable mtv_options. (Not implemented)
#
# See also: plot, semilogx, semilogy, loglog, polar, meshdom, contour,
#           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title

# Created by Ted Harding June 1996
# This file is part of Octave.

if (nargin == 1), z=t; x=y=[]; V=10; endif
if (nargin == 2), z=t; V=u; x=y=[]; endif
if (nargin == 3), x=t; y=u; z=v; V=10; endif
if (nargin == 4), x=t; y=u; z=v; V=w; endif

if (is_matrix (z))
m = columns(z); n = rows(z);
else
error ("mesh: argument must be a matrix");
endif

if (is_vector(x) && is_vector(y))
if (columns(x)==1), x=x'; endif
if (columns(y)==1), y=y'; endif
else
x = (1:m); y = (1:n);
endif

z = flipud(z);

file = "/tmp/mtv_curves_dat";
FILENUM = fopen(file,"a");
fprintf(FILENUM,"\n\n\$ data=CONTOUR\n\n");
%%
%% For non-rectangular-grid data (e.g. polar) try e.g.
%% printf(FILENUM,"\n\n\$ data=CONTCURVE\n\n");
%% instead of the above line.
%%
fprintf(FILENUM,"%% xlabel=\"\"\n");
fprintf(FILENUM,"%% ylabel=\"\"\n");
fprintf(FILENUM,"%% zlabel=\"\"\n");
fprintf(FILENUM,"%% toplabel=\"\"\n");
fprintf(FILENUM,"%% subtitle=\"\"\n");
fprintf(FILENUM,"%% contstyle=2\n\n");

fprintf(FILENUM,"%% hiddenline=True\n");
fprintf(FILENUM,"%% eyepos.y=%g\n",-sqrt(3));
fprintf(FILENUM,"%% eyepos.x=%g\n",1);
fprintf(FILENUM,"%% eyepos.z=%g\n",2*tan(pi/18));
if (is_scalar(V))
fprintf(FILENUM,"%% nsteps = %d\n",V);
else
fprintf(FILENUM,"%% contours=(");
fprintf(FILENUM," %.3g",V);
fprintf(FILENUM,")\n");
endif
fprintf(FILENUM,"%% nx = %d xgrid=True\n",m);
fprintf(FILENUM," %.3g",x);fprintf(FILENUM,"\n");
fprintf(FILENUM,"\n%% ny = %d ygrid=True\n",n);
fprintf(FILENUM," %.3g",y);fprintf(FILENUM,"\n");
fprintf(FILENUM,"%% binary=True\n");
fclose(FILENUM);
z = fliplr(z');
save -mat-binary /tmp/temp.mat z
mtv_cmd = sprintf("system(\"tail -c %.0f /tmp/temp.mat >> %s\")", \
8*m*n, file);
eval(mtv_cmd);

shell_cmd("plotmtv -3d -geom 688x572+80+0 -nodate -noframe \
/tmp/mtv_curves_dat > /dev/null &");
endfunction

===================================================================

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 10-Jun-99                                       Time: 01:16:24
------------------------------ XFMail ------------------------------

---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]