Mercurial > hg > octave-nkf
annotate scripts/geometry/delaunay.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 90450db218e4 |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1999-2011 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 -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9271
diff
changeset
|
20 ## @deftypefn {Function File} {@var{tri} =} delaunay (@var{x}, @var{y}) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{tri} =} delaunay (@var{x}, @var{y}, @var{opt}) |
6823 | 22 ## The return matrix of size [n, 3] contains a set triangles which are |
23 ## described by the indices to the data point x and y vector. | |
9070
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
24 ## The triangulation satisfies the Delaunay circum-circle criterion. |
e9dc2ed2ec0f
Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
25 ## No other data point is in the circum-circle of the defining triangle. |
6823 | 26 ## |
27 ## A third optional argument, which must be a string, contains extra options | |
28 ## passed to the underlying qhull command. See the documentation for the | |
29 ## Qhull library for details. | |
30 ## | |
31 ## @example | |
32 ## @group | |
6826 | 33 ## x = rand (1, 10); |
34 ## y = rand (size (x)); | |
35 ## T = delaunay (x, y); | |
36 ## X = [x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1))]; | |
37 ## Y = [y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1))]; | |
38 ## axis ([0,1,0,1]); | |
39 ## plot (X, Y, "b", x, y, "r*"); | |
6823 | 40 ## @end group |
41 ## @end example | |
42 ## @seealso{voronoi, delaunay3, delaunayn} | |
43 ## @end deftypefn | |
44 | |
6826 | 45 ## Author: Kai Habel <kai.habel@gmx.de> |
6823 | 46 |
6826 | 47 function ret = delaunay (x, y, opt) |
6823 | 48 |
6826 | 49 if (nargin != 2 && nargin != 3) |
6823 | 50 print_usage (); |
51 endif | |
52 | |
10943
90450db218e4
Allow the delaunay function to treat matrices of the same size for compatibility
David Bateman <dbateman@free.fr>
parents:
10793
diff
changeset
|
53 if ((isvector (x) && isvector (y) && length (x) == length (y)) |
90450db218e4
Allow the delaunay function to treat matrices of the same size for compatibility
David Bateman <dbateman@free.fr>
parents:
10793
diff
changeset
|
54 || size_equal (x, y)) |
6823 | 55 if (nargin == 2) |
6826 | 56 tri = delaunayn ([x(:), y(:)]); |
9271
1e96773920e9
geometry/delaunay.m: support cellstr's as options
Soren Hauberg <hauberg@gmail.com>
parents:
9245
diff
changeset
|
57 elseif (ischar (opt) || iscellstr (opt)) |
6826 | 58 tri = delaunayn ([x(:), y(:)], opt); |
6823 | 59 else |
6826 | 60 error ("delaunay: third argument must be a string"); |
6823 | 61 endif |
62 else | |
10943
90450db218e4
Allow the delaunay function to treat matrices of the same size for compatibility
David Bateman <dbateman@free.fr>
parents:
10793
diff
changeset
|
63 error ("delaunay: first two input arguments must be matrices of same size"); |
6823 | 64 endif |
65 | |
6826 | 66 if (nargout == 0) |
67 x = x(:).'; | |
68 y = y(:).'; | |
69 X = [x(tri(:,1)); x(tri(:,2)); x(tri(:,3)); x(tri(:,1))]; | |
70 Y = [y(tri(:,1)); y(tri(:,2)); y(tri(:,3)); y(tri(:,1))]; | |
6823 | 71 plot(X, Y, 'b', x, y, 'r*'); |
72 else | |
73 ret = tri; | |
74 endif | |
75 endfunction | |
76 | |
8153
ec0a13863eb7
Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents:
7017
diff
changeset
|
77 %!testif HAVE_QHULL |
6823 | 78 %! x = [-1, 0, 1, 0, 0]; |
79 %! y = [0, 1, 0, -1, 0]; | |
80 %! assert (sortrows (sort (delaunay (x, y), 2)), [1,2,5;1,4,5;2,3,5;3,4,5]) | |
81 | |
82 %!demo | |
83 %! rand ('state', 1); | |
84 %! x = rand(1,10); | |
85 %! y = rand(size(x)); | |
86 %! T = delaunay(x,y); | |
87 %! X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ]; | |
88 %! Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ]; | |
89 %! axis([0,1,0,1]); | |
90 %! plot(X,Y,'b',x,y,'r*'); |