]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/trisurf.m
update packages
[CreaPhase.git] / octave_packages / m / plot / trisurf.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} {} 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})}.
26 ##
27 ## The optional return value @var{h} is a graphics handle to the created plot.
28 ## @seealso{triplot, trimesh, delaunay3}
29 ## @end deftypefn
30
31 function h = trisurf (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     if (nargin > 4 && isnumeric (varargin{1}))
43       c = varargin{1};
44       varargin(1) = [];
45     else
46       c = z;
47     endif
48     if (! any (strcmpi (varargin, "FaceColor")))
49       nfc = numel (varargin) + 1;
50       varargin(nfc+(0:1)) = {"FaceColor", "flat"};
51     else
52       nfc = find (any (strcmpi (varargin, "FaceColor")), 1);
53     endif
54     if (! any (strcmpi (varargin, "EdgeColor"))
55         && strcmpi (varargin{nfc+1}, "interp"))
56       varargin(end+(1:2)) = {"EdgeColor", "none"};
57     endif
58     newplot ();
59     handle = patch ("Faces", tri, "Vertices", [x(:), y(:), z(:)],
60                     "FaceVertexCData", reshape (c, numel (c), 1),
61                     varargin{:});
62     if (nargout > 0)
63       h = handle;
64     endif
65
66     if (! ishold ())
67       set (gca(), "view", [-37.5, 30],
68            "xgrid", "on", "ygrid", "on", "zgrid", "on");
69     endif
70   endif
71
72 endfunction
73
74 %!demo
75 %! clf
76 %! N = 31;
77 %! [x, y] = meshgrid (1:N);
78 %! tri = delaunay (x, y);
79 %! z = peaks (N);
80 %! h = trisurf (tri, x, y, z, "facecolor", "interp");
81 %! axis tight
82 %! zlim auto
83 %! title (sprintf ("facecolor = %s", get (h, "facecolor")))
84
85 %!demo
86 %! clf
87 %! N = 31;
88 %! [x, y] = meshgrid (1:N);
89 %! tri = delaunay (x, y);
90 %! z = peaks (N);
91 %! h = trisurf (tri, x, y, z, "facecolor", "flat");
92 %! axis tight
93 %! zlim auto
94 %! title (sprintf ("facecolor = %s", get (h, "facecolor")))
95
96 %!demo
97 %! clf
98 %! old_state = rand ("state");
99 %! restore_state = onCleanup (@() rand ("state", old_state));
100 %! rand ("state", 10);
101 %! N = 10;
102 %! x = 3 - 6 * rand (N, N);
103 %! y = 3 - 6 * rand (N, N);
104 %! z = peaks (x, y);
105 %! tri = delaunay (x(:), y(:));
106 %! trisurf (tri, x(:), y(:), z(:));
107
108 %!demo
109 %! clf
110 %! x = rand (100, 1);
111 %! y = rand (100, 1);
112 %! z = x.^2 + y.^2;
113 %! tri = delaunay (x, y);
114 %! trisurf (tri, x, y, z);
115
116 %!demo
117 %! clf
118 %! x = rand (100, 1);
119 %! y = rand (100, 1);
120 %! z = x.^2 + y.^2;
121 %! tri = delaunay (x, y);
122 %! trisurf (tri, x, y, z, "facecolor", "interp");
123
124 %!demo
125 %! clf
126 %! x = rand (100, 1);
127 %! y = rand (100, 1);
128 %! z = x.^2 + y.^2;
129 %! tri = delaunay (x, y);
130 %! trisurf (tri, x, y, z, "facecolor", "interp", "edgecolor", "k");
131