1 ## Copyright (C) 2000-2012 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{H} =} convhull (@var{x}, @var{y})
21 ## @deftypefnx {Function File} {@var{H} =} convhull (@var{x}, @var{y}, @var{options})
22 ## Compute the convex hull of the set of points defined by the
23 ## vectors @var{x} and @var{y}. The hull @var{H} is an index vector into
24 ## the set of points and specifies which points form the enclosing hull.
26 ## An optional third argument, which must be a string or cell array of strings,
27 ## contains options passed to the underlying qhull command.
28 ## See the documentation for the Qhull library for details
29 ## @url{http://www.qhull.org/html/qh-quick.htm#options}.
30 ## The default option is @code{@{"Qt"@}}.
32 ## If @var{options} is not present or @code{[]} then the default arguments are
33 ## used. Otherwise, @var{options} replaces the default argument list.
34 ## To append user options to the defaults it is necessary to repeat the
35 ## default arguments in @var{options}. Use a null string to pass no arguments.
37 ## @seealso{convhulln, delaunay, voronoi}
40 ## Author: Kai Habel <kai.habel@gmx.de>
42 function H = convhull (x, y, options)
44 if (nargin != 2 && nargin != 3)
48 if (! (isvector (x) && isvector (y) && length (x) == length (y))
49 && ! size_equal (x, y))
50 error ("convhull: X and Y must be the same size");
51 elseif (nargin == 3 && ! (ischar (options) || iscellstr (options)))
52 error ("convhull: OPTIONS must be a string or cell array of strings");
56 i = convhulln ([x(:), y(:)]);
58 i = convhulln ([x(:), y(:)], options);
69 next_idx = find (i == next_i);
71 if (rem (next_idx, 2) == 0)
73 next_i = i(next_idx - 1);
77 next_i = i(next_idx + 1);
90 %! k = convhull (x, y);
91 %! plot (x(k),y(k),"r-;convex hull;", x,y,"b+;points;");
92 %! axis ([-3.05, 3.05, -0.05, 1.05]);
97 %! assert (convhull (x, y), [1;7;13;12;11;10;4;3;2;1])
99 %% FIXME: Need input validation tests