Mercurial > hg > octave-lyh
annotate scripts/geometry/voronoi.m @ 8347:fa78cb8d8a5c
corrections for typos
Here is a patch with some corrections for typos and missing/extra
words in the manual.
changeset: 8347:34fd1d1c2294
user: Brian Gough <bjg@gnu.org>
date: Wed Nov 26 11:00:15 2008 -0500
summary: [docs] can not => cannot
author | Brian Gough<bjg@network-theory.co.uk> |
---|---|
date | Thu, 27 Nov 2008 10:28:24 +0100 |
parents | a730e47fda4d |
children | e792c736b1ac |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2000, 2007 Kai Habel |
6823 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6823 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6823 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} voronoi (@var{x}, @var{y}) | |
21 ## @deftypefnx {Function File} {} voronoi (@var{x}, @var{y}, "plotstyle") | |
22 ## @deftypefnx {Function File} {} voronoi (@var{x}, @var{y}, "plotstyle", @var{options}) | |
23 ## @deftypefnx {Function File} {[@var{vx}, @var{vy}] =} voronoi (@dots{}) | |
24 ## plots voronoi diagram of points @code{(@var{x}, @var{y})}. | |
25 ## The voronoi facets with points at infinity are not drawn. | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7208
diff
changeset
|
26 ## [@var{vx}, @var{vy}] = voronoi(...) returns the vertices instead of plotting the |
6823 | 27 ## diagram. plot (@var{vx}, @var{vy}) shows the voronoi diagram. |
28 ## | |
29 ## A fourth optional argument, which must be a string, contains extra options | |
30 ## passed to the underlying qhull command. See the documentation for the | |
31 ## Qhull library for details. | |
32 ## | |
33 ## @example | |
34 ## @group | |
6826 | 35 ## x = rand (10, 1); |
36 ## y = rand (size (x)); | |
37 ## h = convhull (x, y); | |
38 ## [vx, vy] = voronoi (x, y); | |
39 ## plot (vx, vy, "-b", x, y, "o", x(h), y(h), "-g") | |
40 ## legend ("", "points", "hull"); | |
6823 | 41 ## @end group |
42 ## @end example | |
43 ## | |
44 ## @seealso{voronoin, delaunay, convhull} | |
45 ## @end deftypefn | |
46 | |
47 ## Author: Kai Habel <kai.habel@gmx.de> | |
48 ## First Release: 20/08/2000 | |
49 | |
50 ## 2002-01-04 Paul Kienzle <pkienzle@users.sf.net> | |
51 ## * limit the default graph to the input points rather than the whole diagram | |
52 ## * provide example | |
53 ## * use unique(x,"rows") rather than __unique_rows__ | |
54 | |
55 ## 2003-12-14 Rafael Laboissiere <rafael@laboissiere.net> | |
56 ## Added optional fourth argument to pass options to the underlying | |
57 ## qhull command | |
58 | |
59 function [vvx, vvy] = voronoi (varargin) | |
60 | |
61 if (nargin < 1) | |
62 print_usage (); | |
63 endif | |
64 | |
65 narg = 1; | |
66 if (isscalar (varargin{1}) && ishandle (varargin{1})) | |
67 handl = varargin{1}; | |
68 narg++; | |
6826 | 69 if (! strcmp (get (handl, "type"), "axes")) |
6823 | 70 error ("voronoi: expecting first argument to be an axes object"); |
71 endif | |
72 else | |
73 if (nargout < 2) | |
6826 | 74 handl = gca (); |
6823 | 75 endif |
76 endif | |
77 | |
78 if (nargin < 1 + narg || nargin > 3 + narg) | |
79 print_usage (); | |
80 endif | |
81 | |
82 x = varargin{narg++}; | |
83 y = varargin{narg++}; | |
84 | |
85 opts = {}; | |
86 if (narg <= nargin) | |
87 if (iscell (varargin{narg})) | |
88 opts = varargin(narg++); | |
89 elseif (ismatrix (varargin{narg})) | |
90 ## Accept but ignore the triangulation | |
91 narg++; | |
92 endif | |
93 endif | |
94 | |
95 linespec = {"b"}; | |
96 if (narg <= nargin) | |
97 if (ischar (varargin{narg})) | |
98 linespec = varargin(narg); | |
99 endif | |
100 endif | |
101 | |
102 lx = length (x); | |
103 ly = length (y); | |
104 | |
105 if (lx != ly) | |
106 error ("voronoi: arguments must be vectors of same length"); | |
107 endif | |
108 | |
6852 | 109 ## Add big box to approximate rays to infinity |
110 xmax = max (x(:)); | |
111 xmin = min (x(:)); | |
112 ymax = max (y(:)); | |
113 ymin = min (y(:)); | |
114 xdelta = xmax - xmin; | |
115 ydelta = ymax - ymin; | |
116 scale = 10e4; | |
117 | |
118 xbox = [xmin - scale * xdelta; xmin - scale * xdelta; ... | |
119 xmax + scale * xdelta; xmax + scale * xdelta]; | |
120 ybox = [xmin - scale * xdelta; xmax + scale * xdelta; ... | |
121 xmax + scale * xdelta; xmin - scale * xdelta]; | |
122 x = [x(:) ; xbox(:)]; | |
123 y = [y(:) ; ybox(:)]; | |
124 | |
125 [p, c, infi] = __voronoi__ ([x(:), y(:)], opts{:}); | |
6823 | 126 |
127 idx = find (!infi); | |
128 | |
129 ll = length (idx); | |
130 k = 0;r = 1; | |
131 | |
6852 | 132 for i = 1 : ll |
6823 | 133 k += length (c{idx(i)}); |
134 endfor | |
135 | |
136 edges = zeros (2, k); | |
137 | |
6852 | 138 for i = 1 : ll |
7208 | 139 fac = c{idx(i)}; |
6852 | 140 lf = length (fac); |
6823 | 141 fac = [fac, fac(1)]; |
6852 | 142 fst = fac (1 : length(fac) - 1); |
143 sec = fac(2 : length(fac)); | |
144 edges (:, r : r + lf - 1) = [fst; sec]; | |
6823 | 145 r += lf; |
146 endfor | |
147 | |
148 ## Identify the unique edges of the Voronoi diagram | |
149 edges = sortrows (sort (edges).').'; | |
6852 | 150 edges = edges (:, [(edges(1, 1: end - 1) != edges(1, 2 : end) | ... |
151 edges(2, 1 :end - 1) != edges(2, 2 : end)), true]); | |
152 | |
153 ## Eliminate the edges of the diagram representing the box | |
154 poutside = (1 : rows(p)) ... | |
155 (p (:, 1) < xmin - xdelta | p (:, 1) > xmax + xdelta | ... | |
156 p (:, 2) < ymin - ydelta | p (:, 2) > ymax + ydelta); | |
157 edgeoutside = ismember (edges (1, :), poutside) & ... | |
158 ismember (edges (2, :), poutside); | |
159 edges (:, edgeoutside) = []; | |
6823 | 160 |
161 ## Get points of the diagram | |
6852 | 162 vx = reshape (p (edges, 1), size(edges)); |
163 vy = reshape (p (edges, 2), size(edges)); | |
6823 | 164 |
165 if (nargout < 2) | |
6852 | 166 lim = [xmin, xmax, ymin, ymax]; |
6823 | 167 h = plot (handl, vx, vy, linespec{:}, x, y, '+'); |
6852 | 168 axis (lim + 0.1 * [[-1, 1] * (lim (2) - lim (1)), ... |
169 [-1, 1] * (lim (4) - lim (3))]); | |
6823 | 170 if (nargout == 1) |
171 vxx = h; | |
172 endif | |
173 elseif (nargout == 2) | |
174 vvx = vx; | |
175 vvy = vy; | |
176 else | |
177 error ("voronoi: only two or zero output arguments supported") | |
178 endif | |
179 | |
180 endfunction |