1 ## Copyright (C) 2007-2012 David Bateman
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{T} =} delaunayn (@var{pts})
21 ## @deftypefnx {Function File} {@var{T} =} delaunayn (@var{pts}, @var{options})
22 ## Compute the Delaunay triangulation for an N-dimensional set of points.
23 ## The Delaunay triangulation is a tessellation of the convex hull of a set
24 ## of points such that no N-sphere defined by the N-triangles contains
25 ## any other points from the set.
27 ## The input matrix @var{pts} of size [n, dim] contains n points in a space of
28 ## dimension dim. The return matrix @var{T} has size [m, dim+1]. Each row
29 ## of @var{T} contains a set of indices back into the original set of points
30 ## @var{pts} which describes a simplex of dimension dim. For example, a 2-D
31 ## simplex is a triangle and 3-D simplex is a tetrahedron.
33 ## An optional second argument, which must be a string or cell array of strings,
34 ## contains options passed to the underlying qhull command.
35 ## See the documentation for the Qhull library for details
36 ## @url{http://www.qhull.org/html/qh-quick.htm#options}.
37 ## The default options depend on the dimension of the input:
40 ## @item 2-D and 3-D: @var{options} = @code{@{"Qt", "Qbb", "Qc", "Qz"@}}
42 ## @item 4-D and higher: @var{options} = @code{@{"Qt", "Qbb", "Qc", "Qx"@}}
45 ## If @var{options} is not present or @code{[]} then the default arguments are
46 ## used. Otherwise, @var{options} replaces the default argument list.
47 ## To append user options to the defaults it is necessary to repeat the
48 ## default arguments in @var{options}. Use a null string to pass no arguments.
50 ## @seealso{delaunay, delaunay3, convhulln, voronoin}
53 function T = delaunayn (pts, varargin)
59 T = __delaunayn__ (pts, varargin{:});
61 if (isa (pts, "single"))
62 myeps = eps ("single");
67 ## Try to remove the zero volume simplices. The volume of the i-th simplex is
68 ## given by abs(det(pts(T(i,1:end-1),:)-pts(T(i,2:end),:)))/prod(1:n)
69 ## (reference http://en.wikipedia.org/wiki/Simplex). Any simplex with a
70 ## relative volume less than some arbitrary criteria is rejected. The
71 ## criteria we use is the volume of the simplex corresponding to an
72 ## orthogonal simplex is equal edge length all equal to the edge length of
73 ## the original simplex. If the relative volume is 1e3*eps then the simplex
74 ## is rejected. Note division of the two volumes means that the factor
75 ## prod(1:n) is dropped.
78 ## FIXME: Vectorize this for loop or convert to delaunayn to .oct function
80 X = pts(T(i,1:end-1),:) - pts(T(i,2:end),:);
81 if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * myeps)
90 %% FIXME: Need tests for delaunayn
92 %% FIXME: Need input validation tests