www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conellipsoid/constraintDistance.m

    function g = constraintDistance(obj, X)
%CONSTRAINTDISTANCE Signed distance to constraint boundary for a list of points
% 
%  D = CONSTRAINTDISTANCE(CON, X) is the signed distance to the boundary of the
%  constraint CON for the list of points X. This method constitutes the core
%  definition of the constraint in terms of what is in and what is out.
% 
%  X should be an array with nFactors( CON ) columns. D will be a vector with
%  the same number of rows as X.
%
%  See also CONELLIPSOID, CONBASE/CONSTRAINTDISTANCE, CONELLIPSOID/ISINSIDE.

%  Copyright 2000-2007 The MathWorks, Inc. and Ford Global Technologies, Inc.

X = pFilterFactors( obj, X );

n = size( X, 1 );
X = X - obj.xc(ones( 1, n ),:);

% Old form of the distance function
%>> g = obj.scalefactor .* ( sum( (X * obj.W) .* X, 2 ) - 1 );
% Note that this has quadratic growth

% New form:
% Take the sqrt to get the right growth rate and hence the ability to combine
% nicely in boolean combinations. 
g = obj.scalefactor .* ( sqrt( sum( (X * obj.W) .* X, 2 ) ) - 1 ) - obj.Offset;

%------------------------------------------------------------------------------|
% EOF
%------------------------------------------------------------------------------|