]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/trimesh.m
update packages
[CreaPhase.git] / octave_packages / m / plot / trimesh.m
1 ## Copyright (C) 2007-2012 David Bateman
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} trimesh (@var{tri}, @var{x}, @var{y}, @var{z})
21 ## @deftypefnx {Function File} {@var{h} =} trimesh (@dots{})
22 ## Plot a triangular mesh in 3D@.  The variable @var{tri} is the triangular
23 ## meshing of the points @code{(@var{x}, @var{y})} which is returned
24 ## from @code{delaunay}.  The variable @var{z} is value at the point
25 ## @code{(@var{x}, @var{y})}.
26 ##
27 ## The optional return value @var{h} is a graphics handle to the created plot.
28 ## @seealso{triplot, trisurf, delaunay3}
29 ## @end deftypefn
30
31 function h = trimesh (tri, x, y, z, varargin)
32
33   if (nargin < 3)
34     print_usage ();
35   endif
36
37   if (nargin == 3)
38     triplot (tri, x, y);
39   elseif (ischar (z))
40     triplot (tri, x, y, z, varargin{:});
41   else
42     newplot ();
43     handle = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri,
44                     "FaceColor", "none", "EdgeColor", __next_line_color__(),
45                     varargin{:});
46     if (! ishold ())
47       set (gca(), "view", [-37.5, 30],
48            "xgrid", "on", "ygrid", "on", "zgrid", "on");
49     endif
50     if (nargout > 0)
51       h = handle;
52     endif
53   endif
54
55 endfunction
56
57
58 %!demo
59 %! clf
60 %! old_state = rand ("state");
61 %! restore_state = onCleanup (@() rand ("state", old_state));
62 %! rand ("state", 10);
63 %! N = 10;
64 %! x = 3 - 6 * rand (N, N);
65 %! y = 3 - 6 * rand (N, N);
66 %! z = peaks (x, y);
67 %! tri = delaunay (x(:), y(:));
68 %! trimesh (tri, x(:), y(:), z(:));
69