changelog shortlog tags changeset files revisions annotate raw

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
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
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
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
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
18
19## -*- texinfo -*-
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.
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
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*");
40## @end group
41## @end example
42## @seealso{voronoi, delaunay3, delaunayn}
43## @end deftypefn
44
45## Author: Kai Habel <kai.habel@gmx.de>
46
47function ret = delaunay (x, y, opt)
48
49 if (nargin != 2 && nargin != 3)
50 print_usage ();
51 endif
52
53 if (isvector (x) && isvector (y) && length (x) == length (y))
54 if (nargin == 2)
55 tri = delaunayn ([x(:), y(:)]);
56 elseif (ischar (opt) || iscellstr (opt))
57 tri = delaunayn ([x(:), y(:)], opt);
58 else
59 error ("delaunay: third argument must be a string");
60 endif
61 else
62 error ("delaunay: first two input arguments must be vectors of same size");
63 endif
64
65 if (nargout == 0)
66 x = x(:).';
67 y = y(:).';
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*');
71 else
72 ret = tri;
73 endif
74endfunction
75
76%!testif HAVE_QHULL
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])
80
81%!demo
82%! rand ('state', 1);
83%! x = rand(1,10);
84%! y = rand(size(x));
85%! T = delaunay(x,y);
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)) ];
88%! axis([0,1,0,1]);
89%! plot(X,Y,'b',x,y,'r*');