annotate scripts/plot/draw/surfnorm.m @ 20393:4e7f12a763cd stable

doc: Remove typo of same word twice in a row. * data.cc (nzmax), mappers.cc (isinf), contourc.m, cylinder.m, ellipsoid.m: Remove typo of same word twice in a row.
author Rik <rik@octave.org>
date Tue, 12 May 2015 10:05:02 -0700
parents 9fc020886ae9
children 9f484edd8767
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19794
diff changeset
1 ## Copyright (C) 2007-2015 David Bateman
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
2 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
4 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
8 ## your option) any later version.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
9 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
14 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
18
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10634
diff changeset
20 ## @deftypefn {Function File} {} surfnorm (@var{x}, @var{y}, @var{z})
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
21 ## @deftypefnx {Function File} {} surfnorm (@var{z})
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ## @deftypefnx {Function File} {} surfnorm (@dots{}, @var{prop}, @var{val}, @dots{})
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
23 ## @deftypefnx {Function File} {} surfnorm (@var{hax}, @dots{})
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
24 ## @deftypefnx {Function File} {[@var{nx}, @var{ny}, @var{nz}] =} surfnorm (@dots{})
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
25 ## Find the vectors normal to a meshgridded surface.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
26 ##
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ## If @var{x} and @var{y} are vectors, then a typical vertex is
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ## (@var{x}(j), @var{y}(i), @var{z}(i,j)). Thus, columns of @var{z} correspond
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## to different @var{x} values and rows of @var{z} correspond to different
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ## @var{y} values. If only a single input @var{z} is given then @var{x} is
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## taken to be @code{1:rows (@var{z})} and @var{y} is
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
32 ## @code{1:columns (@var{z})}.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
33 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
34 ## If no return arguments are requested, a surface plot with the normal
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
35 ## vectors to the surface is plotted.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
36 ##
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## Any property/value input pairs are assigned to the surface object.
19794
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19793
diff changeset
38 ##
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
39 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
40 ## rather than the current axes returned by @code{gca}.
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
41 ##
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
42 ## If output arguments are requested then the components of the normal
19230
9e3c35d934ab doc: Periodic spell check of documentation.
Rik <rik@octave.org>
parents: 19137
diff changeset
43 ## vectors are returned in @var{nx}, @var{ny}, and @var{nz} and no plot is
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
44 ## made.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
45 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
46 ## An example of the use of @code{surfnorm} is
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
47 ##
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
48 ## @example
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
49 ## surfnorm (peaks (25));
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
50 ## @end example
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
51 ##
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 ## Algorithm: The normal vectors are calculated by taking the cross product
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 ## of the diagonals of each of the quadrilaterals in the meshgrid to find the
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
54 ## normal vectors of the centers of these quadrilaterals. The four nearest
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 ## normal vectors to the meshgrid points are then averaged to obtain the
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
56 ## normal to the surface at the meshgridded points.
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
57 ##
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
58 ## @seealso{isonormals, quiver3, surf, meshgrid}
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
59 ## @end deftypefn
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
60
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
61 function [Nx, Ny, Nz] = surfnorm (varargin)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
62
17052
1118d566bcd4 surf.m, surfc.m, surfl.m, surfnorm.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14872
diff changeset
63 [hax, varargin, nargin] = __plt_get_axis_arg__ ("surfnorm", varargin{:});
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
64
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
65 if (nargin == 0 || nargin == 2)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
66 print_usage ();
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
67 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
68
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7208
diff changeset
69 if (nargin == 1)
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
70 z = varargin{1};
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
71 [x, y] = meshgrid (1:columns (z), 1:rows (z));
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
72 ioff = 2;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
73 else
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
74 x = varargin{1};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
75 y = varargin{2};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
76 z = varargin{3};
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
77 ioff = 4;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
78 endif
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
79
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
80 if (iscomplex (z) || iscomplex (x) || iscomplex (y))
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
81 error ("surfnorm: X, Y, and Z must be 2-D real matrices");
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
82 endif
10634
60542efcfa2c Check input arguments for size and type (bug #29861).
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
83 if (! size_equal (x, y, z))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
84 error ("surfnorm: X, Y, and Z must have the same dimensions");
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
85 endif
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
86
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
87 ## Do a linear extrapolation for mesh points on the boundary so that the mesh
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
88 ## is increased by 1 on each side. This allows each original meshgrid point
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
89 ## to be surrounded by four quadrilaterals and the same calculation can be
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
90 ## used for interior and boundary points. The extrapolation works badly for
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
91 ## closed surfaces like spheres.
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
92 xx = [2 * x(:,1) - x(:,2), x, 2 * x(:,end) - x(:,end-1)];
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
93 xx = [2 * xx(1,:) - xx(2,:); xx; 2 * xx(end,:) - xx(end-1,:)];
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
94 yy = [2 * y(:,1) - y(:,2), y, 2 * y(:,end) - y(:,end-1)];
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
95 yy = [2 * yy(1,:) - yy(2,:); yy; 2 * yy(end,:) - yy(end-1,:)];
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
96 zz = [2 * z(:,1) - z(:,2), z, 2 * z(:,end) - z(:,end-1)];
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
97 zz = [2 * zz(1,:) - zz(2,:); zz; 2 * zz(end,:) - zz(end-1,:)];
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
98
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
99 u.x = xx(1:end-1,1:end-1) - xx(2:end,2:end);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
100 u.y = yy(1:end-1,1:end-1) - yy(2:end,2:end);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
101 u.z = zz(1:end-1,1:end-1) - zz(2:end,2:end);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
102 v.x = xx(1:end-1,2:end) - xx(2:end,1:end-1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
103 v.y = yy(1:end-1,2:end) - yy(2:end,1:end-1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
104 v.z = zz(1:end-1,2:end) - zz(2:end,1:end-1);
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
105
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
106 c = cross ([u.x(:), u.y(:), u.z(:)], [v.x(:), v.y(:), v.z(:)]);
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
107 w.x = reshape (c(:,1), size (u.x));
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
108 w.y = reshape (c(:,2), size (u.y));
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14335
diff changeset
109 w.z = reshape (c(:,3), size (u.z));
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
110
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
111 ## Create normal vectors as mesh vectices from normals at mesh centers
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
112 nx = (w.x(1:end-1,1:end-1) + w.x(1:end-1,2:end) +
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
113 w.x(2:end,1:end-1) + w.x(2:end,2:end)) / 4;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
114 ny = (w.y(1:end-1,1:end-1) + w.y(1:end-1,2:end) +
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
115 w.y(2:end,1:end-1) + w.y(2:end,2:end)) / 4;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
116 nz = (w.z(1:end-1,1:end-1) + w.z(1:end-1,2:end) +
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
117 w.z(2:end,1:end-1) + w.z(2:end,2:end)) / 4;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
118
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
119 ## FIXME: According to Matlab documentation the vertex normals
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
120 ## returned are not normalized.
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
121 ## Normalize the normal vectors
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
122 len = sqrt (nx.^2 + ny.^2 + nz.^2);
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
123 nx ./= len;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
124 ny ./= len;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
125 nz ./= len;
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
126
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
127 if (nargout == 0)
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
128 oldfig = [];
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
129 if (! isempty (hax))
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
130 oldfig = get (0, "currentfigure");
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
131 endif
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
132 unwind_protect
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
133 hax = newplot (hax);
19790
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
134
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
135 surf (x, y, z, varargin{ioff:end});
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
136 old_hold_state = get (hax, "nextplot");
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
137 unwind_protect
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
138 set (hax, "nextplot", "add");
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
139
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
140 ## FIXME: Scale unit normals by data aspect ratio in order for
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
141 ## normals to appear correct.
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
142 ##daratio = daspect (hax);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
143 ##daspect ("manual");
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
144 ##len = norm (daratio);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
145 ## This assumes an even meshgrid which isn't a great assumption
19794
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19793
diff changeset
146 ##dx = x(1,2) - x(1,1);
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19793
diff changeset
147 ##dy = y(2,1) - y(1,1);
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
148 ##nx *= daratio(1);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
149 ##ny *= daratio(2);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
150 ##nz *= daratio(3);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
151 ##len = sqrt (nx.^2 + ny.^2 + nz.^2);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
152 ##nx ./= len;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
153 ##ny ./= len;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
154 ##nz ./= len;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
155 plot3 ([x(:).'; x(:).' + nx(:).' ; NaN(size(x(:).'))](:),
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
156 [y(:).'; y(:).' + ny(:).' ; NaN(size(y(:).'))](:),
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
157 [z(:).'; z(:).' + nz(:).' ; NaN(size(z(:).'))](:),
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
158 "r");
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
159 unwind_protect_cleanup
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
160 set (hax, "nextplot", old_hold_state);
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
161 end_unwind_protect
19790
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
162
17476
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
163 unwind_protect_cleanup
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
164 if (! isempty (oldfig))
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
165 set (0, "currentfigure", oldfig);
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
166 endif
f0f4b524b6d0 maint: Correct indentation for several plot routines.
Rik <rik@octave.org>
parents: 17301
diff changeset
167 end_unwind_protect
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
168 else
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
169 Nx = nx;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
170 Ny = ny;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
171 Nz = nz;
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
172 endif
7216
5389a52df87b [project @ 2007-11-29 19:07:29 by jwe]
jwe
parents: 7215
diff changeset
173
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
174 endfunction
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
175
14223
ba7a26030214 Use Octave spacing convention in %!test blocks of surface plot functions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
176
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
177 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
178 %! clf;
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
179 %! colormap ('default');
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
180 %! surfnorm (peaks (32));
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
181 %! shading interp;
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
182 %! title ({'surfnorm() shows surface and normals at each vertex', ...
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
183 %! 'peaks() function with 32 faces'});
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
184
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents:
diff changeset
185 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
186 %! clf;
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
187 %! colormap ('default');
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
188 %! [x, y, z] = sombrero (10);
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
189 %! surfnorm (x, y, z);
8790
a013ff655ca4 Trivial changes to demos to produce a more pleasant output for octave+gnuplot+aquaterm.
Ben Abbott <bpabbott@mac.com>
parents: 8241
diff changeset
190
20038
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19898
diff changeset
191 ## Test input validation
19137
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
192 %!error surfnorm ()
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
193 %!error surfnorm (1,2)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
194 %!error <X, Y, and Z must be 2-D real matrices> surfnorm (i)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
195 %!error <X, Y, and Z must be 2-D real matrices> surfnorm (i, 1, 1)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
196 %!error <X, Y, and Z must be 2-D real matrices> surfnorm (1, i, 1)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
197 %!error <X, Y, and Z must be 2-D real matrices> surfnorm (1, 1, i)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
198 %!error <X, Y, and Z must have the same dimensions> surfnorm ([1 2], 1, 1)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
199 %!error <X, Y, and Z must have the same dimensions> surfnorm (1, [1 2], 1)
91f626902d17 surfnorm.m: Overhaul for Matlab compatibility.
Rik <rik@octave.org>
parents: 17744
diff changeset
200 %!error <X, Y, and Z must have the same dimensions> surfnorm (1, 1, [1 2])
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14223
diff changeset
201