annotate scripts/plot/surfl.m @ 14335:ce2b59a6d0e5

maint: periodic merge of stable to default.
author Rik <octave@nomad.inbox5.com>
date Sun, 05 Feb 2012 15:32:24 -0800
parents 48cb466f1418 4d917a6a858b
children 5d3a684236b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14092
diff changeset
1 ## Copyright (C) 2009-2012 Kai Habel
8450
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 -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {} surfl (@var{x}, @var{y}, @var{z})
8450
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})
11563
3c6e8aaa9555 Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## @deftypefnx {Function File} {} surfl (@dots{}, "light")
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
25 ## Plot a lighted surface given matrices @var{x}, and @var{y} from
14248
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
26 ## @code{meshgrid} and a matrix @var{z} corresponding to the @var{x} and
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
27 ## @var{y} coordinates of the mesh. If @var{x} and @var{y} are vectors, then
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
28 ## a typical vertex is (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
29 ## of @var{z} correspond to different @var{x} values and rows of @var{z}
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
30 ## correspond to different @var{y} values.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
31 ##
14248
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
32 ## The light direction can be specified using @var{L}. It can be given as a
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
33 ## 2-element vector [azimuth, elevation] in degrees or as a 3-element vector
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
34 ## [lx, ly, lz]. The default value is rotated 45 degrees counterclockwise
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
35 ## from the current view.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
36 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
37 ## 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
38 ## @var{P} = [@var{AM} @var{D} @var{SP} @var{exp}] which defaults to
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
39 ## @var{p} = [0.55 0.6 0.4 10].
14248
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
40 ##
11595
5ec6aa05638d Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
41 ## @table @asis
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
42 ## @item "AM" strength of ambient light
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
43 ##
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
44 ## @item "D" strength of diffuse reflection
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
45 ##
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
46 ## @item "SP" strength of specular reflection
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
47 ##
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
48 ## @item "EXP" specular exponent
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
49 ## @end table
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
50 ##
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
51 ## The default lighting mode "cdata", changes the cdata property to give the
14248
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
52 ## impression of a lighted surface. Please note: the alternative "light"
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
53 ## mode, which creates a light object to illuminate the surface is not
48cb466f1418 surfl.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
54 ## implemented (yet).
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
55 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
56 ## Example:
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
57 ##
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
58 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
59 ## @group
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 ## colormap (bone (64));
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 ## surfl (peaks);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
62 ## shading interp;
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 9040
diff changeset
63 ## @end group
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
64 ## @end example
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
65 ## @seealso{surf, diffuse, specular, surface}
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
66 ## @end deftypefn
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
67
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
68 ## 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
69
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
70 function retval = surfl (varargin)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
71
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
72 [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
73
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
74 oldh = gca ();
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
75 unwind_protect
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
76 axes (h);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
77 newplot ();
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
78
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
79 ## Check for lighting type.
8450
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 if (ischar (varargin{end}))
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
82 lstr = tolower (varargin{end});
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
83 if (strncmp (lstr, "light", 5))
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
84 warning ("light method not supported (yet), using cdata method instead");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10226
diff changeset
85 ## 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
86 use_cdata = false;
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
87 elseif (strncmp (lstr, "cdata", 5))
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
88 use_cdata = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
89 else
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
90 error ("surfl: unknown lighting method");
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
91 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
92 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
93 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
94
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
95 ## Check for reflection properties argument.
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
96 ##
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
97 ## r = [ambient light strength,
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
98 ## diffuse reflection strength,
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
99 ## specular reflection strength,
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
100 ## specular shine]
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
101 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
102 r = varargin{end};
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
103 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
104 else
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
105 ## Default values.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
106 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
107 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
108
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
109 ## 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
110 have_lv = false;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
111 if (isnumeric (varargin{end}))
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
112 len = numel (varargin{end});
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
113 lastarg = varargin{end};
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
114 if (len == 3)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
115 lv = lastarg;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
116 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
117 have_lv = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
118 elseif (len == 2)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
119 [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
120 varargin(end) = [];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
121 have_lv = true;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
122 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
123 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
124
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
125 htmp = surface (varargin{:});
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
126 if (! ishold ())
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
127 set (h, "view", [-37.5, 30],
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10226
diff changeset
128 "xgrid", "on", "ygrid", "on", "zgrid", "on", "clim", [0 1]);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
129 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
130
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
131 ## Get view vector (vv).
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
132 a = axis;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
133 [az, el] = view;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
134 [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
135 vv /= norm (vv);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
136
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
137 if (!have_lv)
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
138 ## 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
139 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
140 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
141 sin(Phi), cos(Phi), 0;
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
142 0, 0, 1];
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
143 lv = (R * vv.').';
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
144 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
145
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
146 vn = get (htmp, "vertexnormals");
10226
2884758e265b Replace dataaspectratio props with plotboxaspectratio props.
Ben Abbott <bpabbott@mac.com>
parents: 9051
diff changeset
147 dar = get (h, "plotboxaspectratio");
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
148 vn(:,:,1) *= dar(1);
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
149 vn(:,:,2) *= dar(2);
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
150 vn(:,:,3) *= dar(3);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
151
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
152 ## Normalize vn.
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
153 vn = vn ./ repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]);
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
154 [nr, nc] = size(get(htmp, "zdata"));
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
155
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
156 ## Ambient, diffuse, and specular term.
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
157 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
158 + 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
159 + 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
160
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
161 set (htmp, "cdata", cdata ./ sum (r(1:3)));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11563
diff changeset
162
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
163 unwind_protect_cleanup
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
164 axes (oldh);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
165 end_unwind_protect
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
166
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
167 if (nargout > 0)
14225
f0d903879eaa Replace unnecessary strcmpi calls with strcmp.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
168 retval = htmp;
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
169 endif
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 endfunction
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
172
14223
ba7a26030214 Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
173
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
174 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
175 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
176 %! [X,Y,Z] = sombrero ();
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
177 %! colormap (copper (64));
14223
ba7a26030214 Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
178 %! surfl (X,Y,Z);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
179 %! shading interp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
180
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
181 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
182 %! clf;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
183 %! [X,Y,Z] = sombrero ();
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
184 %! colormap (copper (64));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14225
diff changeset
185 %! [az, el] = view ();
14223
ba7a26030214 Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
186 %! surfl (X,Y,Z, [az+225,el], [0.2 0.6 0.4 25]);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
187 %! shading interp;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
188