Mercurial > hg > octave-lyh
annotate scripts/geometry/delaunayn.m @ 11188:4cb1522e4d0f
Use function handle as input to cellfun,
rather than quoted function name or anonymous function wrapper.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 03 Nov 2010 17:20:56 -0700 |
parents | 693e22af08ae |
children | c776f063fefe |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2008, 2009 David Bateman |
6823 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6823 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6823 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {@var{T} =} delaunayn (@var{P}) |
6846 | 21 ## @deftypefnx {Function File} {@var{T} =} delaunayn (@var{P}, @var{opt}) |
6823 | 22 ## Form the Delaunay triangulation for a set of points. |
23 ## The Delaunay triangulation is a tessellation of the convex hull of the | |
24 ## points such that no n-sphere defined by the n-triangles contains | |
6826 | 25 ## any other points from the set. |
26 ## The input matrix @var{P} of size @code{[n, dim]} contains @var{n} | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## points in a space of dimension dim. The return matrix @var{T} has the |
6826 | 28 ## size @code{[m, dim+1]}. It contains for each row a set of indices to |
29 ## the points, which describes a simplex of dimension dim. For example, | |
30 ## a 2d simplex is a triangle and 3d simplex is a tetrahedron. | |
6823 | 31 ## |
32 ## Extra options for the underlying Qhull command can be specified by the | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
33 ## second argument. This argument is a cell array of strings. The default |
6823 | 34 ## options depend on the dimension of the input: |
35 ## | |
36 ## @itemize | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
37 ## @item 2D and 3D: @var{opt} = @code{@{"Qt", "Qbb", "Qc"@}} |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
38 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## @item 4D and higher: @var{opt} = @code{@{"Qt", "Qbb", "Qc", "Qz"@}} |
6826 | 40 ## @end itemize |
6823 | 41 ## |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
42 ## If @var{opt} is [], then the default arguments are used. If @var{opt} |
6826 | 43 ## is @code{@{"@w{}"@}}, then none of the default arguments are used by Qhull. |
6823 | 44 ## See the Qhull documentation for the available options. |
45 ## | |
46 ## All options can also be specified as single string, for example | |
6826 | 47 ## @code{"Qt Qbb Qc Qz"}. |
6823 | 48 ## |
49 ## @end deftypefn | |
50 | |
51 function t = delaunayn (x, varargin) | |
52 if (nargin < 1) | |
6826 | 53 print_usage (); |
6823 | 54 endif |
55 | |
7208 | 56 t = __delaunayn__ (x, varargin{:}); |
6823 | 57 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
58 if (isa (x, "single")) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
59 myeps = eps ("single"); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
60 else |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
61 myeps = eps; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
62 endif |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
63 |
6823 | 64 ## Try to remove the zero volume simplices. The volume of the i-th simplex is |
65 ## given by abs(det(x(t(i,1:end-1),:)-x(t(i,2:end),:)))/prod(1:n) | |
66 ## (reference http://en.wikipedia.org/wiki/Simplex). Any simplex with a | |
67 ## relative volume less than some arbitrary criteria is rejected. The | |
68 ## criteria we use is the volume of the simplex corresponding to an | |
69 ## orthogonal simplex is equal edge length all equal to the edge length of | |
70 ## the original simplex. If the relative volume is 1e3*eps then the simplex | |
71 ## is rejected. Note division of the two volumes means that the factor | |
72 ## prod(1:n) is dropped. | |
73 idx = []; | |
6826 | 74 [nt, n] = size (t); |
75 for i = 1:nt | |
6823 | 76 X = x(t(i,1:end-1),:) - x(t(i,2:end),:); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7208
diff
changeset
|
77 if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * myeps) |
6823 | 78 idx = [idx, i]; |
79 endif | |
80 endfor | |
81 t(idx,:) = []; | |
82 endfunction |