scripts/geometry/delaunay.m
| changeset 10289: |
4b124317dc38 |
| parent: | 16f53d29049f |
| author: |
John W. Eaton <jwe@octave.org> |
| date: |
Tue Feb 09 20:58:55 2010 -0500 (64 minutes ago) |
| permissions: |
-rw-r--r-- |
| description: |
base_properties::set_children: account for hidden children |
1## Copyright (C) 1999, 2000, 2007, 2008, 2009 Kai Habel
3## This file is part of Octave.
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
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
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.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {@var{tri} =} delaunay (@var{x}, @var{y})
21## @deftypefnx {Function File} {@var{tri} =} delaunay (@var{x}, @var{y}, @var{opt})
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.
24## The triangulation satisfies the Delaunay circum-circle criterion.
25## No other data point is in the circum-circle of the defining triangle.
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.
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))];
39## plot (X, Y, "b", x, y, "r*");
42## @seealso{voronoi, delaunay3, delaunayn}
45## Author: Kai Habel <kai.habel@gmx.de>
47function ret = delaunay (x, y, opt)
49 if (nargin != 2 && nargin != 3)
53 if (isvector (x) && isvector (y) && length (x) == length (y))
55 tri = delaunayn ([x(:), y(:)]);
56 elseif (ischar (opt) || iscellstr (opt))
57 tri = delaunayn ([x(:), y(:)], opt);
59 error ("delaunay: third argument must be a string");
62 error ("delaunay: first two input arguments must be vectors of same size");
68 X = [x(tri(:,1)); x(tri(:,2)); x(tri(:,3)); x(tri(:,1))];
69 Y = [y(tri(:,1)); y(tri(:,2)); y(tri(:,3)); y(tri(:,1))];
70 plot(X, Y, 'b', x, y, 'r*');
77%! x = [-1, 0, 1, 0, 0];
78%! y = [0, 1, 0, -1, 0];
79%! assert (sortrows (sort (delaunay (x, y), 2)), [1,2,5;1,4,5;2,3,5;3,4,5])
86%! X = [ x(T(:,1)); x(T(:,2)); x(T(:,3)); x(T(:,1)) ];
87%! Y = [ y(T(:,1)); y(T(:,2)); y(T(:,3)); y(T(:,1)) ];
89%! plot(X,Y,'b',x,y,'r*');