www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conboolean/isInside.m
function true_in = isInside( c, X, in ) %ISINSIDE Check which points from a list are inside a constraint. % % ISINSIDE(CON, X, IN) is a logical vector indicating which points in X % (N-by-nfactors) are within the constrained region. IN is a logical vector % indicating which points to constrain and which to ignore, i.e., which points % are currently considered to be "in" the constrained region. % % AND constraint: the interior of AND( c1, c2, ... ) is the intersection of % the interiors of c1, c2, ... . Therefore to be in AND( c1, c2, ... ) points % must be in at all of c1, c2, ... and thus as soon as a point is found to be % outside one of constraint the others need no be checked. % % OR constraint : the interior of OR( c1, c2, ... ) is the union of the % interiors of c1, c2, ... . Therefore to be inside OR( c1, c2, ... ) points % only need be inside one of c1, c2, ... . However, to be outside OR( c1, c2, % ... ) points must be outside all of c1, c2, ... . % % XOR constraint: to be in XOR( c1, c2 ) points must be in c1 and outside c2 OR % outside c1 and inside c2. % % NOT constraint: to be inside NOT( c1 ) points must be outside c1, i.e., % either CON is a NOT constraint or ISINSIDE( CON ) == ISINSIDE( c1 ) % % ISINSIDE( CON ) = XOR( CON.Not, ISINSIDE( c1 ) ) % % See also CONBOOLEAN % Copyright 2000-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. % The original 'in' is required to get the output right. It is also the % default output if all points are already outside or if the boolean % constraint object has no constraints. true_in = in; % If all the points are outside, i.e., there aren't any in, then there is % nothing to do so just return. if ~any( in ), return end % Number of constraints nc = length( c.Constraints ); if nc == 0, return end % Only consider points that are already 'in' X = X(in,:); in = in(in); % Different process for each type of constraint. switch lower( c.Op ), case 'none', if nc ~= 1, warning(message('mbc:conboolean:InvalidState')); end in = isInside( c.Constraints{1}, X, in ); case 'and', i = 1; while any( in ) && i <= nc, in(in) = isInside( c.Constraints{i}, X(in,:), in(in) ); i = i + 1; end case 'or', % We use the "out" variable to be true for points that are outside the % constraints we have checked so far. % Initially, we haven't checked any comstraints so all the points that % we need to check are outside. out = in; i = 1; while any( out ) && i <= nc, out(out) = ~isInside( c.Constraints{i}, X(out,:), out(out) ); i = i + 1; end in = ~out; case 'xor', if nc ~= 2, warning(message('mbc:conboolean:InvalidState')); end in = xor( ... isInside( c.Constraints{1}, X, in ), ... isInside( c.Constraints{2}, X, in ) ); otherwise warning(message('mbc:conboolean:InvalidState')); end if c.Not % have to deal with points exactly on boundary D= ones(size(X,1),1); D(in) = constraintDistance(c,X(in,:)); % 'not' the constraints or on the boundary in = ~in | D==0; end % Setup output true_in(true_in) = in; % EOF