annotate scripts/plot/surfl.m @ 8762:2476ce55d4b5

typo in gnuplot_drawnow.m
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 16 Feb 2009 15:50:44 +0100
parents e4c9ecb64411
children cf2163418140
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
1 ## Copyright (C) 2009 Kai Habel
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
2 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
3 ## This file is part of Octave.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
4 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
8 ## your option) any later version.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
9 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
13 ## General Public License for more details.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
14 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
18
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
19 ## -*- texinfo -*-
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
20 ## @deftypefn {Function File} {} surfl (@var{x}, @var{y}, @var{z})
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
21 ## @deftypefnx {Function File} {} surfl (@var{z})
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
22 ## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{L})
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
23 ## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{L}, @var{P})
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
24 ## @deftypefnx {Function File} {} surfl (...,"light")
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
25 ## Plot a lighted surface given matrices @var{x}, and @var{y} from @code{meshgrid} and
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
26 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
27 ## the mesh. If @var{x} and @var{y} are vectors, then a typical vertex
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
28 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z}
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
29 ## correspond to different @var{x} values and rows of @var{z} correspond
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
30 ## to different @var{y} values.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
31 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
32 ## The light direction can be specified using @var{L}. It can be
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
33 ## given as 2-element vector [azimuth, elevation] in degrees or as 3-element vector [lx, ly, lz].
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
34 ## The default value is rotated 45° counter-clockwise from the current view.
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
35 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
36 ## The material properties of the surface can specified using a 4-element vector
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
37 ## @var{P} = [@var{AM} @var{D} @var{SP} @var{exp}] which defaults to
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
38 ## @var{p} = [0.55 0.6 0.4 10].
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
39 ## @table @code
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
40 ## @item "AM" strength of ambient light
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
41 ## @item "D" strength of diffuse reflection
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
42 ## @item "SP" strength of specular reflection
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
43 ## @item "EXP" specular exponent
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
44 ## @end table
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
45 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
46 ## The default lighting mode "cdata", changes the cdata property to give the impression
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
47 ## of a lighted surface. Please note: the alternative "light" mode, which creates a light
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
48 ## object to iluminate the the surface is not implemented (yet).
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
49 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
50 ## Example:
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
51 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
52 ## @example
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
53 ## colormap(bone);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
54 ## surfl(peaks);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
55 ## shading interp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
56 ## @end example
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
57 ## @seealso{surf, diffuse, specular, surface}
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
58 ## @end deftypefn
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
59
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
60 ## Author: Kai Habel <kai.habel@gmx.de>
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
61
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
62 function retval = surfl (varargin)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
63
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
64 [h, varargin] = __plt_get_axis_arg__ ("surfl", varargin{:});
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
65
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
66 oldh = gca ();
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
67 unwind_protect
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
68 axes (h);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
69 newplot ();
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
70
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
71 ## Check for lighting type.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
72 use_cdata = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
73 if (ischar (varargin{end}))
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
74 lstr = varargin{end};
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
75 if (strncmp (tolower (lstr), "light", 5))
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
76 warning ("light method not supported (yet), using cdata method instead");
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
77 ## This can be implemented when light objects are supported.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
78 use_cdata = false;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
79 elseif (strncmp (tolower (lstr), "cdata", 5))
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
80 use_cdata = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
81 else
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
82 error ("surfl: unknown lighting method");
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
83 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
84 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
85 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
86
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
87 ## Check for reflection properties argument.
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
88 ##
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
89 ## r = [ambient light strength,
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
90 ## diffuse reflection strength,
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
91 ## specular reflection strength,
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
92 ## specular shine]
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
93 if (length (varargin{end}) == 4 && isnumeric (varargin{end}))
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
94 r = varargin{end};
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
95 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
96 else
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
97 ## Default values.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
98 r = [0.55, 0.6, 0.4, 10];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
99 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
100
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
101 ## Check for light vector (lv) argument.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
102 have_lv = false;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
103 if (isnumeric (varargin{end}))
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
104 len = numel (varargin{end});
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
105 lastarg = varargin{end};
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
106 if (len == 3)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
107 lv = lastarg;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
108 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
109 have_lv = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
110 elseif (len == 2)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
111 [lv(1), lv(2), lv(3)] = sph2cart ((lastarg(1) - 90) * pi/180, lastarg(2) * pi/180, 1.0);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
112 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
113 have_lv = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
114 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
115 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
116
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
117 tmp = surface (varargin{:});
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
118 if (! ishold ())
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
119 set (h, "view", [-37.5, 30],
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
120 "xgrid", "on", "ygrid", "on", "zgrid", "on", "clim", [0 1]);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
121 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
122
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
123 ## Get view vector (vv).
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
124 a = axis;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
125 [az, el] = view;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
126 [vv(1), vv(2), vv(3)] = sph2cart ((az - 90) * pi/180.0, el * pi/180.0, 1.0);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
127 vv /= norm (vv);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
128
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
129 if (!have_lv)
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
130 ## Calculate light vector (lv) from view vector.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
131 Phi = 45.0 / 180.0 * pi;
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
132 R = [cos(Phi), -sin(Phi), 0;
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
133 sin(Phi), cos(Phi), 0;
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
134 0, 0, 1];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
135 lv = (R * vv.').';
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
136 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
137
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
138 vn = get (tmp, "vertexnormals");
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
139 dar = get (h, "dataaspectratio");
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
140 vn(:,:,1) *= dar(1);
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
141 vn(:,:,2) *= dar(2);
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
142 vn(:,:,3) *= dar(3);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
143
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
144 ## Normalize vn.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
145 vn = vn ./ repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
146 [nr, nc] = size(get(tmp, "zdata"));
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
147
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
148 ## Ambient, diffuse, and specular term.
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
149 cdata = (r(1) * ones (nr, nc)
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
150 + r(2) * diffuse (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv)
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
151 + r(3) * specular (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv, vv, r(4)));
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
152
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
153 set (tmp, "cdata", cdata ./ sum (r(1:3)));
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
154
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
155 unwind_protect_cleanup
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
156 axes (oldh);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
157 end_unwind_protect
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
158
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
159 if (nargout > 0)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
160 retval = tmp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
161 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
162
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
163 endfunction
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
164
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
165 %!demo
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
166 %! [X,Y,Z]=sombrero;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
167 %! colormap(copper);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
168 %! surfl(X,Y,Z);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
169 %! shading interp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
170
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
171 %!demo
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
172 %! [X,Y,Z]=sombrero;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
173 %! colormap(copper);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
174 %! [az, el] = view;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
175 %! surfl(X,Y,Z,[az+225,el],[0.2 0.6 0.4 25]);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
176 %! shading interp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
177