1## Copyright (C) 2000, 2007, 2008 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{opt})
22## Returns the index vector to the points of the enclosing convex hull. The
23## data points are defined by the x and y vectors.
25## A third optional argument, which must be a string, contains extra options
26## passed to the underlying qhull command. See the documentation for the
27## Qhull library for details.
29## @seealso{delaunay, convhulln}
32## Author: Kai Habel <kai.habel@gmx.de>
34function H = convhull (x, y, opt)
36 if (nargin != 2 && nargin != 3)
40 if (isvector (x) && isvector (y) && length (x) == length (y))
42 i = convhulln ([x(:), y(:)]);
43 elseif (ischar (opt) || iscell (opt))
44 i = convhulln ([x(:), y(:)], opt);
46 error ("convhull: third argument must be a string or cell array of strings");
49 error ("convhull: first two input arguments must be vectors of same size");
60 next_idx = find (i == next_i);
62 if (rem (next_idx, 2) == 0)
64 next_i = i(next_idx - 1);
68 next_i = i(next_idx + 1);
79%! assert (convhull (x, y, {"s","Qci","Tcv","Pp"}), [1;7;13;12;11;10;4;3;2;1])
84%! k = convhull (x, y);
85%! plot (x(k),y(k),'r-',x,y,'b+');
86%! axis ([-3.05, 3.05, -0.05, 1.05]);