function [Facets,Nrm,Q] = convexh(x,y,z) % CONVEXH Convex hull of arbitrary-dimensional set. % FAC = CONVEXH(R) returns convex hull FAC of a set % with coordinates R. Each row of a matrix R % represents coordinates of a point in a set, % such as [xi yi zi ...] while each row of output % FAC represent indices of points in a facet in a % convex hull. % CONVEXH(X,Y,Z) can be used for 3-d sets with % coordinates X, Y, Z, and is the same as % CONVEXH([X(:) Y(:) Z(:)]). % % [FAC,NRM] = CONVEXH(...) also returns the outer % normal vectors to each facet, size(NRM)=size(FAC). % Copyright (c) 1995 by Kirill K. Pankratov % kirill@plume.mit.edu % 05/05/95 % Handle input ........................................... if nargin==0, help convexh, return, end str_err = ' Error: arguments must be of the same size'; if nargin>1 % Add y to R if length(x(:))~=length(y(:)) error(str_err) end R = [x(:) y(:)]; if nargin>2 % Add z to R if length(x(:))~=length(z(:)) error(str_err) end R = [R z(:)]; end else % 1 input argument R = x; end [n_pts,dim] = size(R); % Dimensions of data set % Check rank of a set, if deficient, reduce dimension % and calculate effective phase space ............... c_fac = mean(R); R = R-c_fac(ones(n_pts,1),:); rnk = rank(R); if nargout>2, Q=eye(dim); end if rnk1); % Outermost point end % Initialize active points mask - zeros for points % belonging to initial facets and their outermost points active_pts = ones(n_pts,1); active_pts(c_fac) = zeros(size(c_fac)); c_fac = find(active_fac); % Sort initial simplex so that active facets are first % Find active facets i_fac = [find(active_fac); find(~active_fac)]; Facets = Facets(i_fac,:); Nrm = Nrm(i_fac,:); active_fac = active_fac(i_fac); while active_fac(1) % While there are "active" facets ``` % Add new point to a convex hull [Facets,Nrm,active_fac,active_pts] = cvxadd(Facets,Nrm,... active_fac,R,active_pts,r0); end % End while (no more active facets) '''''''''''''''''