1 ## Copyright (C) 2007-2012 David Bateman
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} trisurf (@var{tri}, @var{x}, @var{y}, @var{z})
21 ## @deftypefnx {Function File} {@var{h} =} trisurf (@dots{})
22 ## Plot a triangular surface 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})}.
27 ## The optional return value @var{h} is a graphics handle to the created plot.
28 ## @seealso{triplot, trimesh, delaunay3}
31 function h = trisurf (tri, x, y, z, varargin)
40 triplot (tri, x, y, z, varargin{:});
42 if (nargin > 4 && isnumeric (varargin{1}))
48 if (! any (strcmpi (varargin, "FaceColor")))
49 nfc = numel (varargin) + 1;
50 varargin(nfc+(0:1)) = {"FaceColor", "flat"};
52 nfc = find (any (strcmpi (varargin, "FaceColor")), 1);
54 if (! any (strcmpi (varargin, "EdgeColor"))
55 && strcmpi (varargin{nfc+1}, "interp"))
56 varargin(end+(1:2)) = {"EdgeColor", "none"};
59 handle = patch ("Faces", tri, "Vertices", [x(:), y(:), z(:)],
60 "FaceVertexCData", reshape (c, numel (c), 1),
67 set (gca(), "view", [-37.5, 30],
68 "xgrid", "on", "ygrid", "on", "zgrid", "on");
77 %! [x, y] = meshgrid (1:N);
78 %! tri = delaunay (x, y);
80 %! h = trisurf (tri, x, y, z, "facecolor", "interp");
83 %! title (sprintf ("facecolor = %s", get (h, "facecolor")))
88 %! [x, y] = meshgrid (1:N);
89 %! tri = delaunay (x, y);
91 %! h = trisurf (tri, x, y, z, "facecolor", "flat");
94 %! title (sprintf ("facecolor = %s", get (h, "facecolor")))
98 %! old_state = rand ("state");
99 %! restore_state = onCleanup (@() rand ("state", old_state));
100 %! rand ("state", 10);
102 %! x = 3 - 6 * rand (N, N);
103 %! y = 3 - 6 * rand (N, N);
105 %! tri = delaunay (x(:), y(:));
106 %! trisurf (tri, x(:), y(:), z(:));
110 %! x = rand (100, 1);
111 %! y = rand (100, 1);
113 %! tri = delaunay (x, y);
114 %! trisurf (tri, x, y, z);
118 %! x = rand (100, 1);
119 %! y = rand (100, 1);
121 %! tri = delaunay (x, y);
122 %! trisurf (tri, x, y, z, "facecolor", "interp");
126 %! x = rand (100, 1);
127 %! y = rand (100, 1);
129 %! tri = delaunay (x, y);
130 %! trisurf (tri, x, y, z, "facecolor", "interp", "edgecolor", "k");