annotate scripts/plot/appearance/specular.m @ 20266:83792dd9bcc1

Use in-place operators in m-files where possible. * scripts/audio/@audioplayer/set.m, scripts/audio/@audiorecorder/set.m, scripts/audio/mu2lin.m, scripts/elfun/cosd.m, scripts/general/del2.m, scripts/general/profexplore.m, scripts/general/quadl.m, scripts/general/rat.m, scripts/general/rotdim.m, scripts/help/get_first_help_sentence.m, scripts/help/private/__strip_html_tags__.m, scripts/image/cubehelix.m, scripts/io/textread.m, scripts/linear-algebra/duplication_matrix.m, scripts/linear-algebra/housh.m, scripts/linear-algebra/krylov.m, scripts/linear-algebra/logm.m, scripts/linear-algebra/normest.m, scripts/linear-algebra/onenormest.m, scripts/optimization/fminsearch.m, scripts/optimization/lsqnonneg.m, scripts/optimization/qp.m, scripts/plot/appearance/annotation.m, scripts/plot/appearance/axis.m, scripts/plot/appearance/legend.m, scripts/plot/appearance/specular.m, scripts/plot/draw/colorbar.m, scripts/plot/draw/hist.m, scripts/plot/draw/plotmatrix.m, scripts/plot/draw/private/__stem__.m, scripts/plot/util/__actual_axis_position__.m, scripts/plot/util/__gnuplot_drawnow__.m, scripts/plot/util/findobj.m, scripts/plot/util/print.m, scripts/plot/util/private/__go_draw_axes__.m, scripts/plot/util/private/__print_parse_opts__.m, scripts/plot/util/rotate.m, scripts/polynomial/pchip.m, scripts/polynomial/polyaffine.m, scripts/polynomial/polyder.m, scripts/polynomial/private/__splinefit__.m, scripts/polynomial/residue.m, scripts/signal/arch_fit.m, scripts/signal/arch_rnd.m, scripts/signal/bartlett.m, scripts/signal/blackman.m, scripts/signal/freqz.m, scripts/signal/hamming.m, scripts/signal/hanning.m, scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m, scripts/signal/stft.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/private/__sprand_impl__.m, scripts/sparse/qmr.m, scripts/sparse/sprandsym.m, scripts/sparse/svds.m, scripts/specfun/legendre.m, scripts/special-matrix/gallery.m, scripts/statistics/base/gls.m, scripts/statistics/models/logistic_regression.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/manova.m, scripts/statistics/tests/wilcoxon_test.m, scripts/time/datevec.m: Use in-place operators in m-files where possible.
author Rik <rik@octave.org>
date Tue, 26 May 2015 21:07:42 -0700
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18332
diff changeset
1 ## Copyright (C) 2009-2015 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 -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
20 ## @deftypefn {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{lv}, @var{vv})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
21 ## @deftypefnx {Function File} {} specular (@var{sx}, @var{sy}, @var{sz}, @var{lv}, @var{vv}, @var{se})
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ## Calculate the specular reflection strength of a surface defined by the
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ## normal vector elements @var{sx}, @var{sy}, @var{sz} using Phong's
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 ## approximation.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14138
diff changeset
25 ##
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
26 ## The light source location and viewer location vectors are specified using
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ## parameters @var{lv} and @var{vv} respectively. The location vectors can
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14138
diff changeset
28 ## given as 2-element vectors [azimuth, elevation] in degrees or as 3-element
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14138
diff changeset
29 ## vectors [x, y, z].
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14138
diff changeset
30 ##
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## An optional sixth argument specifies the specular exponent (spread) @var{se}.
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## If not given, @var{se} defaults to 10.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14138
diff changeset
33 ## @seealso{diffuse, surfl}
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
34 ## @end deftypefn
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 ## 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
37
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
38 function retval = specular (sx, sy, sz, lv, vv, se)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
39
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
40 if (nargin < 5 || nargin > 6)
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
41 print_usage ();
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
42 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
43
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
44 ## Check normal vectors
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
45 if (! size_equal (sx, sy, sz))
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
46 error ("specular: SX, SY, and SZ must be the same size");
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
47 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
48
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
49 ## Check light vector (lv) argument
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
50 if (! isvector (lv) || length (lv) < 2 || length (lv) > 3)
8460
e4c9ecb64411 diffuse.m, specular.m, surfl.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 8450
diff changeset
51 error ("specular: light vector LV must be a 2- or 3-element vector");
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
52 elseif (length (lv) == 2)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
53 [lv(1), lv(2), lv(3)] = sph2cart (lv(1) * pi/180, lv(2) * pi/180, 1.0);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
54 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
55
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
56 ## Check view vector (vv) argument
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
57 if (! isvector (vv) || length (vv) < 2 || length (lv) > 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 9040
diff changeset
58 error ("specular: view vector VV must be a 2- or 3-element vector");
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
59 elseif (length (vv) == 2)
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
60 [vv(1), vv(2), vv(3)] = sph2cart (vv(1) * pi / 180, vv(2) * pi / 180, 1.0);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
61 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
62
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
63 ## Check specular exponent (se) argument
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
64 if (nargin < 6)
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
65 se = 10;
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
66 elseif (! (isnumeric (se) && numel (se) == 1 && se > 0))
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
67 error ("specular: exponent SE must be a positive scalar");
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
68 endif
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
69
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
70 ## Normalize view and light vectors
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
71 if (sum (abs (lv)) > 0)
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
72 lv /= norm (lv);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
73 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
74 if (sum (abs (vv)) > 0)
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
75 vv /= norm (vv);
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
76 endif
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
77
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
78 ## Calculate normal vector lengths and dot-products
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
79 ns = sqrt (sx.^2 + sy.^2 + sz.^2);
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
80 l_dot_n = (sx * lv(1) + sy * lv(2) + sz * lv(3)) ./ ns;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
81 v_dot_n = (sx * vv(1) + sy * vv(2) + sz * vv(3)) ./ ns;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
82
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
83 ## Calculate specular reflection using Phong's approximation
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
84 retval = 2 * l_dot_n .* v_dot_n - dot (lv, vv);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
85
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
86 ## Set reflectance to zero if light is on the other side
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
87 retval(l_dot_n < 0) = 0;
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
88
18332
925bdd86a479 specular.m: Overhaul function.
Rik <rik@octave.org>
parents: 17744
diff changeset
89 ## Allow postive values only
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
90 retval(retval < 0) = 0;
20266
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 19731
diff changeset
91 retval .^= se;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
92
8450
6c4e2fc14beb Add new 3D plotting function surfl. Add light functions diffuse and specular
Kai Habel
parents:
diff changeset
93 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17122
diff changeset
94