# HG changeset patch # User jwe # Date 1187971327 0 # Node ID 8618f29520c6fefc62d94aaf194edf9a63cfccba # Parent 59e22e30aff870153b0001eec92cf474e261b708 [project @ 2007-08-24 16:02:07 by jwe] diff --git a/scripts/geometry/convhull.m b/scripts/geometry/convhull.m --- a/scripts/geometry/convhull.m +++ b/scripts/geometry/convhull.m @@ -30,29 +30,29 @@ ## @seealso{delaunay, convhulln} ## @end deftypefn -## Author: Kai Habel +## Author: Kai Habel -function H = convhull (x,y,opt) +function H = convhull (x, y, opt) - if ((nargin != 2) && (nargin != 3)) + if (nargin != 2 && nargin != 3) print_usage (); endif - if (isvector(x) && isvector(y) && (length(x) == length(y))) + if (isvector (x) && isvector (y) && length (x) == length (y)) if (nargin == 2) - i = convhulln([x(:), y(:)]); - elseif (ischar(opt) || iscell (opt)) - i = convhulln([x(:), y(:)], opt); + i = convhulln ([x(:), y(:)]); + elseif (ischar (opt) || iscell (opt)) + i = convhulln ([x(:), y(:)], opt); else - error("third argument must be a string or cell array of strings"); + error ("convhull: third argument must be a string or cell array of strings"); endif else - error("first two input arguments must be vectors of same size"); + error ("convhull: first two input arguments must be vectors of same size"); endif - n = rows(i); + n = rows (i); i = i'(:); - H = zeros(n + 1,1); + H = zeros (n + 1, 1); H(1) = i(1); next_i = i(2); diff --git a/scripts/geometry/delaunay.m b/scripts/geometry/delaunay.m --- a/scripts/geometry/delaunay.m +++ b/scripts/geometry/delaunay.m @@ -31,42 +31,43 @@ ## ## @example ## @group -## x = rand(1,10); -## y = rand(size(x)); -## T = delaunay(x,y); -## X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; -## Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; -## axis([0,1,0,1]); -## plot(X,Y,'b',x,y,'r*'); +## x = rand (1, 10); +## y = rand (size (x)); +## T = delaunay (x, y); +## X = [x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1))]; +## Y = [y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1))]; +## axis ([0,1,0,1]); +## plot (X, Y, "b", x, y, "r*"); ## @end group ## @end example ## @seealso{voronoi, delaunay3, delaunayn} ## @end deftypefn -## Author: Kai Habel +## Author: Kai Habel -function ret = delaunay (x,y,opt) +function ret = delaunay (x, y, opt) - if ((nargin != 2) && (nargin != 3)) + if (nargin != 2 && nargin != 3) print_usage (); endif - if (isvector(x) && isvector(y) && (length(x) == length(y))) + if (isvector (x) && isvector (y) && length (x) == length (y)) if (nargin == 2) - tri = delaunayn([x(:), y(:)]); - elseif ischar(opt) - tri = delaunayn([x(:), y(:)], opt); + tri = delaunayn ([x(:), y(:)]); + elseif (ischar (opt)) + tri = delaunayn ([x(:), y(:)], opt); else - error("third argument must be a string"); + error ("delaunay: third argument must be a string"); endif else - error("first two input arguments must be vectors of same size"); + error ("delaunay: first two input arguments must be vectors of same size"); endif - if nargout == 0 - x = x(:).'; y = y(:).'; - X = [ x(tri(:,1)); x(tri(:,2)); x(tri(:,3)); x(tri(:,1)) ]; - Y = [ y(tri(:,1)); y(tri(:,2)); y(tri(:,3)); y(tri(:,1)) ]; + if (nargout == 0) + x = x(:).'; + y = y(:).'; + X = [x(tri(:,1)); x(tri(:,2)); x(tri(:,3)); x(tri(:,1))]; + Y = [y(tri(:,1)); y(tri(:,2)); y(tri(:,3)); y(tri(:,1))]; plot(X, Y, 'b', x, y, 'r*'); else ret = tri; diff --git a/scripts/geometry/delaunay3.m b/scripts/geometry/delaunay3.m --- a/scripts/geometry/delaunay3.m +++ b/scripts/geometry/delaunay3.m @@ -30,25 +30,25 @@ ## @seealso{delaunay,delaunayn} ## @end deftypefn -## Author: Kai Habel +## Author: Kai Habel -function tetr = delaunay3 (x,y,z,opt) +function tetr = delaunay3 (x, y, z, opt) - if ((nargin != 3) && (nargin != 4)) + if (nargin != 3 && nargin != 4) print_usage (); endif - if (isvector(x) && isvector(y) &&isvector(z) && ... - (length(x) == length(y)) && (length(x) == length(z))) + if (isvector (x) && isvector (y) &&isvector (z) + && length (x) == length (y) && length(x) == length (z)) if (nargin == 3) - tetr = delaunayn([x(:),y(:),z(:)]); - elseif (ischar(opt) || iscell (opt)) - tetr = delaunayn([x(:),y(:),z(:)], opt); + tetr = delaunayn ([x(:), y(:), z(:)]); + elseif (ischar (opt) || iscell (opt)) + tetr = delaunayn ([x(:), y(:), z(:)], opt); else - error("delaunay3: fourth argument must be a string or cell array of strings"); + error ("delaunay3: fourth argument must be a string or cell array of strings"); endif else - error("delaunay3: first three input arguments must be vectors of same size"); + error ("delaunay3: first three input arguments must be vectors of same size"); endif endfunction diff --git a/scripts/geometry/delaunayn.m b/scripts/geometry/delaunayn.m --- a/scripts/geometry/delaunayn.m +++ b/scripts/geometry/delaunayn.m @@ -23,34 +23,34 @@ ## Form the Delaunay triangulation for a set of points. ## The Delaunay triangulation is a tessellation of the convex hull of the ## points such that no n-sphere defined by the n-triangles contains -## any other points from the set.\n -## The input matrix @var{P} of size [n, dim] contains n points in a space -## of dimension dim. The return matrix @var{T} has the size [m, dim+1]. It -## contains for each row a set of indices to the points, which describes a -## simplex of dimension dim. For example, a 2d simplex is a triangle and 3d -## simplex is a tetrahedron. +## any other points from the set. +## The input matrix @var{P} of size @code{[n, dim]} contains @var{n} +## points in a space of dimension dim. The return matrix @var{T} has the +## size @code{[m, dim+1]}. It contains for each row a set of indices to +## the points, which describes a simplex of dimension dim. For example, +## a 2d simplex is a triangle and 3d simplex is a tetrahedron. ## ## Extra options for the underlying Qhull command can be specified by the ## second argument. This argument is a cell array of strings. The default ## options depend on the dimension of the input: ## ## @itemize -## @item 2D and 3D: @var{opt} = @{'Qt','Qbb','Qc'@} -## @item 4D and higher: @var{opt} = @{'Qt','Qbb','Qc','Qz'@} -## @end itemize +## @item 2D and 3D: @var{opt} = @code{@{"Qt", "Qbb", "Qc"@}} +## @item 4D and higher: @var{opt} = @code{@{"Qt", "Qbb", "Qc", "Qz"@}} +## @end itemize ## ## If @var{opt} is [], then the default arguments are used. If @var{opt} -## is @{'@w{}'@}, then none of the default arguments are used by Qhull. +## is @code{@{"@w{}"@}}, then none of the default arguments are used by Qhull. ## See the Qhull documentation for the available options. ## ## All options can also be specified as single string, for example -## 'Qt Qbb Qc Qz'. +## @code{"Qt Qbb Qc Qz"}. ## ## @end deftypefn function t = delaunayn (x, varargin) if (nargin < 1) - print_usage() + print_usage (); endif t = __delaunayn__ (x, varargin {:}); @@ -65,8 +65,8 @@ ## is rejected. Note division of the two volumes means that the factor ## prod(1:n) is dropped. idx = []; - [nt, n] = size(t); - for i = 1 : nt + [nt, n] = size (t); + for i = 1:nt X = x(t(i,1:end-1),:) - x(t(i,2:end),:); if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * eps) idx = [idx, i]; diff --git a/scripts/geometry/dsearch.m b/scripts/geometry/dsearch.m --- a/scripts/geometry/dsearch.m +++ b/scripts/geometry/dsearch.m @@ -28,9 +28,9 @@ function idx = dsearch (x, y, t, xi, yi, s) if (nargin < 5 || nargin > 6) - print_usage(); + print_usage (); endif - idx = __dsearchn__ ([x(:),y(:)], [xi(:), yi(:)]); + idx = __dsearchn__ ([x(:), y(:)], [xi(:), yi(:)]); endfunction %!shared x, y, tri diff --git a/scripts/geometry/griddata.m b/scripts/geometry/griddata.m --- a/scripts/geometry/griddata.m +++ b/scripts/geometry/griddata.m @@ -26,8 +26,8 @@ ## The interpolation points are all @code{(@var{xi}, @var{yi})}. If ## @var{xi}, @var{yi} are vectors then they are made into a 2D mesh. ## -## The interpolation method can be 'nearest', 'cubic' or 'linear'. -## If method is omitted it defaults to 'linear'. +## The interpolation method can be @code{"nearest"}, @code{"cubic"} or +## @code{"linear"}. If method is omitted it defaults to @code{"linear"}. ## @seealso{delaunay} ## @end deftypefn @@ -36,64 +36,72 @@ ## xi and yi are not "meshgridded" if both are vectors ## of the same size (for compatibility) -function [rx, ry, rz] = griddata (x,y,z,xi,yi,method) +function [rx, ry, rz] = griddata (x, y, z, xi, yi, method) if (nargin == 5) - method="linear"; + method = "linear"; endif if (nargin < 5 || nargin > 7) - print_usage(); + print_usage (); endif - if (ischar(method)) - method=tolower(method); + if (ischar (method)) + method = tolower (method); endif - if (!all( (size(x)==size(y)) & (size(x)==size(z)))) - error("griddata: x,y,z must be vectors of same length"); + if (! all (size (x) == size (y) & size (x) == size (z))) + error ("griddata: x, y, and z must be vectors of same length"); endif ## meshgrid xi and yi if they are vectors unless they ## are vectors of the same length - if (isvector(xi) && isvector(yi) && numel(xi) ~= numel(yi)) - [xi,yi]=meshgrid(xi,yi); + if (isvector (xi) && isvector (yi) && numel (xi) != numel (yi)) + [xi, yi] = meshgrid (xi, yi); endif - if (any(size(xi) != size(yi))) - error("griddata: xi and yi must be vectors or matrices of same size"); + if (any (size (xi) != size (yi))) + error ("griddata: xi and yi must be vectors or matrices of same size"); endif - [nr,nc] = size(xi); + [nr, nc] = size (xi); ## triangulate data - tri = delaunay(x,y); - zi = nan(size(xi)); + tri = delaunay (x, y); + zi = nan (size (xi)); - if strcmp(method,"cubic") - error("griddata(...,'cubic') cubic interpolation not yet implemented\n") + if (strcmp (method, "cubic")) + error ("griddata: cubic interpolation not yet implemented") - elseif strcmp(method,'nearest') + elseif (strcmp (method, "nearest")) ## search index of nearest point - idx = dsearch(x,y,tri,xi,yi); - valid = !isnan(idx); + idx = dsearch (x, y, tri, xi, yi); + valid = !isnan (idx); zi(valid) = z(idx(valid)); - elseif strcmp(method,'linear') + elseif (strcmp (method, "linear")) ## search for every point the enclosing triangle - tri_list= tsearch(x,y,tri,xi(:),yi(:)); + tri_list= tsearch (x, y, tri, xi(:), yi(:)); ## only keep the points within triangles. - valid = !isnan(reshape(tri_list,size(xi))); - tri_list = tri_list(!isnan(tri_list)); - nr_t = rows(tri_list); + valid = !isnan (reshape (tri_list, size (xi))); + tri_list = tri_list(!isnan (tri_list)); + nr_t = rows (tri_list); ## assign x,y,z for each point of triangle - x1 = x(tri(tri_list,1));y1=y(tri(tri_list,1));z1=z(tri(tri_list,1)); - x2 = x(tri(tri_list,2));y2=y(tri(tri_list,2));z2=z(tri(tri_list,2)); - x3 = x(tri(tri_list,3));y3=y(tri(tri_list,3));z3=z(tri(tri_list,3)); + x1 = x(tri(tri_list,1)); + x2 = x(tri(tri_list,2)); + x3 = x(tri(tri_list,3)); + + y1 = y(tri(tri_list,1)); + y2 = y(tri(tri_list,2)); + y3 = y(tri(tri_list,3)); + + z1 = z(tri(tri_list,1)); + z2 = z(tri(tri_list,2)); + z3 = z(tri(tri_list,3)); ## calculate norm vector - N = cross([x2-x1, y2-y1, z2-z1],[x3-x1, y3-y1, z3-z1]); - N_norm = sqrt(sumsq(N,2)); + N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]); + N_norm = sqrt (sumsq (N, 2)); N = N ./ N_norm(:,[1,1,1]); ## calculate D of plane equation @@ -104,17 +112,17 @@ zi(valid) = -(N(:,1).*xi(valid) + N(:,2).*yi(valid) + D ) ./ N(:,3); else - error("griddata: unknown interpolation method"); + error ("griddata: unknown interpolation method"); endif - if nargout == 3 + if (nargout == 3) rx = xi; ry = yi; rz = zi; - elseif nargout == 1 + elseif (nargout == 1) rx = zi; - elseif nargout == 0 - mesh(xi, yi, zi); + elseif (nargout == 0) + mesh (xi, yi, zi); endif endfunction diff --git a/scripts/geometry/griddata3.m b/scripts/geometry/griddata3.m --- a/scripts/geometry/griddata3.m +++ b/scripts/geometry/griddata3.m @@ -24,34 +24,33 @@ ## The function is defined by @code{@var{y} = f (@var{x},@var{y},@var{z})}. ## The interpolation points are all @var{xi}. ## -## The interpolation method can be 'nearest' or 'linear'. If method is -## omitted it defaults to 'linear'. +## The interpolation method can be @code{"nearest"} or @code{"linear"}. +## If method is omitted it defaults to @code{"linear"}. ## @seealso{griddata, delaunayn} ## @end deftypefn -function [yi] = griddata3 (x,y,z,v,xi,yi,zi,method,varargin) +function [yi] = griddata3 (x, y, z,v, xi, yi, zi, method, varargin) - if (nargin < 7) - print_usage(); + if (nargin < 7) + print_usage (); endif - if (!all( (size(x)==size(y)) & (size(x)==size(z)) & ... - (size(x)==size(v)))) - error("griddata3: x,y,z,v must be vectors of same length"); + if (!all (size (x) == size (y) & size (x) == size(z) & size(x) == size (v))) + error ("griddata3: x, y, z, and v must be vectors of same length"); endif ## meshgrid xi, yi and zi if they are vectors unless they ## are vectors of the same length - if (isvector(xi) && isvector(yi) && isvector(zi) && ... - (numel(xi) != numel(yi) || numel(xi) != numel(zi))) - [xi,yi,zi] = meshgrid(xi,yi,zi); + if (isvector (xi) && isvector (yi) && isvector (zi) + && (numel (xi) != numel (yi) || numel (xi) != numel (zi))) + [xi, yi, zi] = meshgrid (xi, yi, zi); endif - if (any(size(xi) != size(yi)) || any(size(xi) != size(zi))) - error("griddata: xi, yi and zi must be vectors or matrices of same size"); + if (any (size(xi) != size(yi)) || any (size(xi) != size(zi))) + error ("griddata: xi, yi and zi must be vectors or matrices of same size"); endif - vi = gridata ([x(:),y(:),z(:)], v(:), [xi(:),yi(:),zi(:)], varargin{:}); - vi = reshape (vi, size(xi)); + vi = gridata ([x(:), y(:), z(:)], v(:), [xi(:), yi(:), zi(:)], varargin{:}); + vi = reshape (vi, size (xi)); endfunction diff --git a/scripts/geometry/griddatan.m b/scripts/geometry/griddatan.m --- a/scripts/geometry/griddatan.m +++ b/scripts/geometry/griddatan.m @@ -24,63 +24,62 @@ ## The function is defined by @code{@var{y} = f (@var{x})}. ## The interpolation points are all @var{xi}. ## -## The interpolation method can be 'nearest' or 'linear'. If method is -## omitted it defaults to 'linear'. +## The interpolation method can be @code{"nearest"} or @code{"linear"}. +## If method is omitted it defaults to @code{"linear"}. ## @seealso{griddata, delaunayn} ## @end deftypefn -function [yi] = griddatan (x,y,xi,method,varargin) - +function yi = griddatan (x, y, xi, method, varargin) + if (nargin == 3) - method="linear"; + method = "linear"; endif if (nargin < 3) - print_usage(); + print_usage (); endif - if (ischar(method)) - method=tolower(method); + if (ischar (method)) + method = tolower (method); endif - [m, n] = size(x); - [mi, ni] = size(xi); + [m, n] = size (x); + [mi, ni] = size (xi); - if (n != ni || size(y,1) != m || size(y,2) != 1) + if (n != ni || size (y, 1) != m || size (y, 2) != 1) error ("griddatan: dimensional mismatch"); endif ## triangulate data ## tri = delaunayn(x, varargin{:}); - tri = delaunayn(x); + tri = delaunayn (x); - yi = nan(mi, 1); + yi = nan (mi, 1); - if strcmp(method,'nearest') + if (strcmp (method, "nearest")) ## search index of nearest point - idx = dsearchn(x,tri,xi); - valid = !isnan(idx); + idx = dsearchn (x, tri, xi); + valid = !isnan (idx); yi(valid) = y(idx(valid)); - elseif strcmp(method,'linear') + elseif (strcmp (method, "linear")) ## search for every point the enclosing triangle - [tri_list, bary_list] = tsearchn(x,tri,xi); + [tri_list, bary_list] = tsearchn (x, tri, xi); ## only keep the points within triangles. - valid = !isnan(tri_list); - tri_list = tri_list(!isnan(tri_list)); - bary_list = bary_list(!isnan(tri_list), :); - nr_t = rows(tri_list); + valid = !isnan (tri_list); + tri_list = tri_list(!isnan (tri_list)); + bary_list = bary_list(!isnan (tri_list), :); + nr_t = rows (tri_list); ## assign x,y for each point of simplex - xt = reshape (x(tri(tri_list,:),:),[nr_t, n+1, n]); + xt = reshape (x(tri(tri_list,:),:), [nr_t, n+1, n]); yt = y(tri(tri_list,:)); ## Use barycentric coordinate of point to calculate yi yi(valid) = sum (y(tri(tri_list,:)) .* bary_list, 2); else - method - error("griddatan: unknown interpolation method"); + error ("griddatan: unknown interpolation method"); endif endfunction diff --git a/scripts/geometry/trimesh.m b/scripts/geometry/trimesh.m --- a/scripts/geometry/trimesh.m +++ b/scripts/geometry/trimesh.m @@ -30,7 +30,7 @@ function h = trimesh (tri, x, y, z, varargin) if (nargin < 3) - print_usage(); + print_usage (); endif if (nargin == 3) @@ -39,18 +39,18 @@ triplot (tri, x, y, z, varargin{:}); else idx = tri(:, [1,2,3,1]).'; - nt = size(tri, 1); + nt = size (tri, 1); ## FIXME We should really use patch instead of plot3, but we don't ## have a patch function, and probably won't in 3D that works with ## gnuplot if (nargout > 0) - h = plot3([x(idx); NaN*ones(1, nt)](:), ... - [y(idx); NaN*ones(1, nt)](:), ... - [z(idx); NaN*ones(1, nt)](:), varargin{:}); + h = plot3 ([x(idx); NaN*ones(1, nt)](:), + [y(idx); NaN*ones(1, nt)](:), + [z(idx); NaN*ones(1, nt)](:), varargin{:}); else - plot3([x(idx); NaN*ones(1, nt)](:), ... - [y(idx); NaN*ones(1, nt)](:), ... - [z(idx); NaN*ones(1, nt)](:), varargin{:}); + plot3 ([x(idx); NaN*ones(1, nt)](:), + [y(idx); NaN*ones(1, nt)](:), + [z(idx); NaN*ones(1, nt)](:), varargin{:}); endif endif endfunction diff --git a/scripts/geometry/triplot.m b/scripts/geometry/triplot.m --- a/scripts/geometry/triplot.m +++ b/scripts/geometry/triplot.m @@ -32,17 +32,17 @@ function h = triplot (tri, x, y, varargin) if (nargin < 3) - print_usage(); + print_usage (); endif - idx = tri (:, [1, 2, 3, 1]).'; - nt = size(tri, 1); + idx = tri(:, [1, 2, 3, 1]).'; + nt = size (tri, 1); if (nargout > 0) - h = plot([x(idx); NaN*ones(1, nt)](:), ... - [y(idx); NaN*ones(1, nt)](:), varargin{:}); + h = plot ([x(idx); NaN*ones(1, nt)](:), + [y(idx); NaN*ones(1, nt)](:), varargin{:}); else - plot([x(idx); NaN*ones(1, nt)](:), ... - [y(idx); NaN*ones(1, nt)](:), varargin{:}); + plot ([x(idx); NaN*ones(1, nt)](:), + [y(idx); NaN*ones(1, nt)](:), varargin{:}); endif endfunction diff --git a/scripts/geometry/voronoi.m b/scripts/geometry/voronoi.m --- a/scripts/geometry/voronoi.m +++ b/scripts/geometry/voronoi.m @@ -33,11 +33,12 @@ ## ## @example ## @group -## x = rand(10,1); y = rand(size(x)); -## h = convhull(x,y); -## [vx,vy] = voronoi(x,y); -## plot(vx, vy, "-b", x, y, "o", x(h), y(h), "-g") -## legend("", "points", "hull"); +## x = rand (10, 1); +## y = rand (size (x)); +## h = convhull (x, y); +## [vx, vy] = voronoi (x, y); +## plot (vx, vy, "-b", x, y, "o", x(h), y(h), "-g") +## legend ("", "points", "hull"); ## @end group ## @end example ## @@ -66,13 +67,12 @@ if (isscalar (varargin{1}) && ishandle (varargin{1})) handl = varargin{1}; narg++; - obj = get (handl); - if (! strcmp (obj.type, "axes")) + if (! strcmp (get (handl, "type"), "axes")) error ("voronoi: expecting first argument to be an axes object"); endif else if (nargout < 2) - handl = gca(); + handl = gca (); endif endif diff --git a/scripts/geometry/voronoin.m b/scripts/geometry/voronoin.m --- a/scripts/geometry/voronoin.m +++ b/scripts/geometry/voronoin.m @@ -40,7 +40,7 @@ function [C, F] = voronoin (pts, opt) - if ((nargin != 1) && (nargin != 2)) + if (nargin != 1 && nargin != 2) print_usage (); endif @@ -51,7 +51,7 @@ elseif ischar(opt) [C, F, infi] = __voronoi__ (pts, opt); else - error("second argument must be a string"); + error ("voronoin: second argument must be a string"); endif else