annotate scripts/geometry/convhull.m @ 33632:fed0dc6fd44c default tip

remove unused variable from libgui/module.mk * libgui/module.mk: remove empty variable OCTAVE_GUI_EDITOR_MOC
author Torsten Lilge <ttl-octave@mailbox.org>
date Mon, 27 May 2024 19:42:05 +0200
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2000-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
7 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
8 ## This file is part of Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
14 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
19 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6846
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
25
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## @deftypefn {} {@var{H} =} convhull (@var{x}, @var{y})
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
28 ## @deftypefnx {} {@var{H} =} convhull (@var{x}, @var{y}, @var{z})
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
29 ## @deftypefnx {} {@var{H} =} convhull (@var{x})
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
30 ## @deftypefnx {} {@var{H} =} convhull (@dots{}, @var{options})
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
31 ## @deftypefnx {} {[@var{H}, @var{V}] =} convhull (@dots{})
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
32 ## Compute the convex hull of a 2-D or 3-D set of points.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
33 ##
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
34 ## The hull @var{H} is a linear index vector into the original set of points
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
35 ## that specifies which points form the enclosing hull. For 2-D inputs only,
26293
095eb3a04f43 doc: grammarcheck m-file scripts ahead of 5.0 release.
Rik <rik@octave.org>
parents: 26141
diff changeset
36 ## the output is ordered in a counterclockwise manner around the hull.
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
37 ##
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
38 ## The input @var{x} may also be a matrix with two or three columns where the
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
39 ## first column contains x-data, the second y-data, and the optional third
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
40 ## column contains z-data.
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
41 ##
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
42 ## An optional final argument, which must be a string or cell array of strings,
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
43 ## contains options passed to the underlying qhull command.
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
44 ## See the documentation for the Qhull library for details
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
45 ## @url{http://www.qhull.org/html/qh-quick.htm#options}.
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
46 ## The default option is @code{@{"Qt"@}}.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
47 ##
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
48 ## If @var{options} is not present or @code{[]} then the default arguments are
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
49 ## used. Otherwise, @var{options} replaces the default argument list.
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
50 ## To append user options to the defaults it is necessary to repeat the
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
51 ## default arguments in @var{options}. Use a null string to pass no arguments.
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
52 ##
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
53 ## If the second output @var{V} is requested the volume of the enclosing
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
54 ## convex hull is calculated.
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
55 ##
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
56 ## @seealso{convhulln, delaunay, voronoi}
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
57 ## @end deftypefn
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
58
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
59 function [H, V] = convhull (varargin)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
60
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
61 if (nargin < 1 || nargin > 4)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
62 print_usage ();
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
63 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
64
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
65 z = [];
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
66 options = [];
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
67
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
68 switch (nargin)
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
69
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
70 case 1
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
71 if (! ismatrix (varargin{1})
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
72 || (columns (varargin{1}) != 2 && columns (varargin{1}) != 3))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
73 error ("convhull: X must be a matrix with 2 or 3 columns");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
74 else
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
75 x = varargin{1}(:,1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
76 y = varargin{1}(:,2);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
77 if (columns (varargin{1}) == 3)
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
78 z = varargin{1}(:,3);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
79 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
80 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
81
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
82 case 2
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
83 if (isnumeric (varargin{2}))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
84 x = varargin{1};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
85 y = varargin{2};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
86 elseif (! (ischar (varargin{2}) || iscellstr (varargin{2})))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
87 error ("convhull: OPTIONS must be a string or cell array of strings");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
88 else
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
89 options = varargin{2};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
90 ncols = columns (varargin{1});
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
91
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
92 if (! ismatrix (varargin{1}) || (ncols != 2 && ncols != 3))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
93 error ("convhull: X must be a matrix with 2 or 3 columns");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
94 else
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
95 x = varargin{1}(:,1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
96 y = varargin{1}(:,2);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
97 if (ncols == 3)
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
98 z = varargin{1}(:,3);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
99 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
100 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
101 endif
14267
527ed2a51d54 convhull.m: Allow non-vector arguments, for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14237
diff changeset
102
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
103 case 3
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
104 if (isnumeric (varargin{3}))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
105 x = varargin{1};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
106 y = varargin{2};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
107 z = varargin{3};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
108 elseif (! (ischar (varargin{3}) || iscellstr (varargin{3})))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
109 error ("convhull: OPTIONS must be a string or cell array of strings");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
110 else
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
111 x = varargin{1};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
112 y = varargin{2};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
113 options = varargin{3};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
114 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
115
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
116 case 4
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
117 x = varargin{1};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
118 y = varargin{2};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
119 z = varargin{3};
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
120 options = varargin{4};
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
121
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
122 if (! (ischar (options) || iscellstr (options)))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
123 error ("convhull: OPTIONS must be a string or cell array of strings");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
124 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
125
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
126 endswitch
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
127
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
128 if (isempty (z))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
129 x = x(:); y = y(:);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
130 if (! size_equal (x, y))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
131 error ("convhull: X and Y must be the same size");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
132 endif
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
133 if (nargout > 1)
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
134 [Htmp, V] = convhulln ([x, y], options);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
135 else
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
136 Htmp = convhulln ([x, y], options);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
137 endif
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
138 else
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
139 x = x(:); y = y(:); z = z(:);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
140 if (! size_equal (x, y, z))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
141 error ("convhull: X, Y, and Z must be the same size");
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
142 endif
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
143 if (nargout > 1)
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
144 [H, V] = convhulln ([x, y, z], options);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
145 else
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
146 H = convhulln ([x, y, z], options);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
147 endif
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
148 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
149
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
150 if (isempty (z))
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
151 ## Order 2-D convex hull in a counter-clockwise manner.
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
152 n = rows (Htmp);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
153 Htmp = Htmp.'(:);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
154 H = zeros (n + 1, 1);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
155
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
156 H(1) = Htmp(1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
157 next_pt = Htmp(2);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
158 Htmp(2) = 0;
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
159 for k = 2:n
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
160 next_idx = find (Htmp == next_pt);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
161 H(k) = Htmp(next_idx);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
162
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
163 if (rem (next_idx, 2) == 0)
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
164 next_pt = Htmp(next_idx - 1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
165 Htmp(next_idx - 1) = 0;
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
166 else
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
167 next_pt = Htmp(next_idx + 1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
168 Htmp(next_idx + 1) = 0;
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
169 endif
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
170 endfor
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
171
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
172 H(n + 1) = H(1);
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
173 endif
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
174
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
175 endfunction
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
176
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
177
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
178 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
179 %! clf;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
180 %! x = -3:0.05:3;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
181 %! y = abs (sin (x));
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
182 %! k = convhull (x, y);
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
183 %! plot (x(k),y(k),"r-;convex hull;", x,y,"b+;points;");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
184 %! axis ([-3.05, 3.05, -0.05, 1.05]);
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
185
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
186 %!testif HAVE_QHULL
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
187 %! x = -3:0.5:3;
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
188 %! y = abs (sin (x));
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14278
diff changeset
189 %! assert (convhull (x, y), [1;7;13;12;11;10;4;3;2;1]);
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
190
26141
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
191 %!testif HAVE_QHULL
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
192 %! [~, V] = convhull ([0,2,2,0], [0,0,1,1]);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
193 %! assert (V == 2);
42a06f8e6966 convhull.m: Calculate second output (Volume of hull) for compatibility (bug #55106).
Rik <rik@octave.org>
parents: 26098
diff changeset
194
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
195 ## Input validation tests
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
196 %!error <Invalid call> convhull ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27923
diff changeset
197 %!error <Invalid call> convhull (1,2,3,4,5)
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
198 %!error <X must be a matrix with 2 or 3 columns> convhull (ones (2,4))
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
199 %!error <OPTIONS must be a string or cell array> convhull (ones (2,2), struct ())
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
200 %!error <X must be a matrix with 2 or 3 columns> convhull (ones (2,4), "")
28912
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
201 %!error <OPTIONS must be a string or cell array> convhull (ones (2,2), ones (2,2), struct ())
0de38a6ef693 maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents: 28896
diff changeset
202 %!error <OPTIONS must be a string or cell array> convhull (ones (2,2), ones (2,2), ones (2,2), struct ())
26098
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
203 %!error <X and Y must be the same size> convhull (1, [1 2])
e97a0d4ed5d0 convhull.m: Overhaul function to allow 1 and 3 input calling formis (bug #53979).
Rik <rik@octave.org>
parents: 25054
diff changeset
204 %!error <X, Y, and Z must be the same size> convhull (1, [1 2], [1 2])