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

    function d = constraintDistance(con, 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. 
%
%  To ensure that the distance is on the right scale, the formula for computing
%  the distance for a range constraint is
%
%             D(i) = max( (abs( X(i,:) - C ) - W)./SC )
%
%  where C is the center and W is the half-width for the constraint and SC is
%  the scale factor from the range of the input factors.
%
%  See also CONRANGE, CONBASE/CONSTRAINTDISTANCE.

%  Copyright 2000-2006 The MathWorks, Inc.

% Compute the scale factor from the active factors
%   The scale factor is half the length of the range for each factor

% we are only using a subset of the inputs
X = pFilterFactors( con, X);

% Compute the distances for each factor
i = ones( size( X, 1 ), 1 );
d = (abs( X - con.Center(i,:) ) - con.HalfWidth(i,:))./con.ScaleFactor(i,:);

% The actual distance is just the max over all factors.
d = max( d, [], 2 );

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